You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Apple Pay按钮资源?自定义PKPaymentButton高度失败求助

解决PKPaymentButton自定义高度失败及Apple Pay资源获取问题

我之前也踩过PKPaymentButton高度约束的坑,系统默认的30高度约束确实有点“顽固”,同时Apple Pay资源的入口也容易找错,下面给你详细的解决方案:

一、自定义PKPaymentButton高度的正确姿势

PKPaymentButton的内部高度约束优先级很高,直接移除或禁用往往无效,试试这两种方法:

方法1:强制覆盖约束(推荐)

先关闭按钮的自动约束转换,再添加你自己的高度约束,确保你的约束优先级是最高的(1000):

let applePayButton = PKPaymentButton(paymentButtonType: .buy, paymentButtonStyle: .black)
// 关键:关闭自动约束生成
applePayButton.translatesAutoresizingMaskIntoConstraints = false
// 添加自定义高度及其他布局约束
NSLayoutConstraint.activate([
    applePayButton.heightAnchor.constraint(equalToConstant: 50), // 替换成你要的高度
    applePayButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
    applePayButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
    applePayButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])

方法2:调低系统约束优先级

如果方法1还是不生效,可以遍历按钮的内部约束,把系统的高度约束优先级调低,让你的约束生效:

for constraint in applePayButton.constraints {
    if constraint.firstAttribute == .height {
        constraint.priority = UILayoutPriority.defaultHigh // 设置为750,低于你的约束优先级
    }
}
// 再添加你的高度约束
applePayButton.heightAnchor.constraint(equalToConstant: 50).isActive = true

二、获取Apple Pay官方图片资源

Apple Pay的官方标识资源需要登录开发者账号后获取,路径是:

  • 登录开发者后台后,找到「Apple Pay」板块
  • 进入「品牌与营销资源」(或类似命名的板块),里面有可下载的按钮SVG/PNG文件、使用规范文档
  • 注意:下载后必须严格遵循Apple的使用指南,不能随意修改按钮的颜色、比例或样式

内容的提问来源于stack exchange,提问作者Canucklesandwich

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 07:51:28