koi*_*ira 6 interface-builder ios swift applepay
以下代码来自WWDC 2015 Session 702 Apple Pay in Apps - Emporium:Apple Pay的简单购物体验
if PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(ProductTableViewController.supportedNetworks) {
let button = PKPaymentButton(type: .Buy, style: .Black)
button.addTarget(self, action: #selector(ProductTableViewController.applePayButtonPressed), forControlEvents: .TouchUpInside)
button.center = applePayView.center
button.autoresizingMask = [.FlexibleLeftMargin, .FlexibleRightMargin]
applePayView.addSubview(button)
}
Run Code Online (Sandbox Code Playgroud)
我想知道我们是否可以在IB中创建这个按钮.
我也在寻找这个,结果证明可以使用 IB 来设置它。只需在 IB 中创建一个 UIButton,将其类型设置为 PKPaymentButton,现在在 UserDefinedRuntimeAttributes 中根据需要设置“style”和“type”,对应于 PKPaymentButtonStyle 和 PKPaymentButtonType。例如:
type = 1 //corresponding to - PKPaymentButtonTypeBuy
style = 2 //corresponding to - PKPaymentButtonStyleBlack
Run Code Online (Sandbox Code Playgroud)
这就是你最终得到的:
附注。有趣的是,您可以在 IB 属性中设置 cornerRadius,但正如您所见,它不会影响按钮。似乎即使在代码中设置它也没有任何作用。因此,如果您不想被矩形 PKPaymentButton 卡住 - 只需将它放在一个视图中,您将其圆角并确保Clip to Bounds在 IB (或在代码中yourButtonHolder.clipsToBounds = true)打勾
您可以通过编辑自定义类字段来更改 Interface Builder 中身份检查器中按钮的类。此时您为其创建的插座应该是 PKPaymentButton 类型。
| 归档时间: |
|
| 查看次数: |
1986 次 |
| 最近记录: |