我正在按照Braintree的指南将dropIn功能添加到iOS应用中。为了显示dropIn,我使用以下方法:
func showDropIn(clientTokenOrTokenizationKey: String) {
let request = BTDropInRequest()
let dropIn = BTDropInController(authorization: clientTokenOrTokenizationKey, request: request)
{ (controller, result, error) in
if (error != nil) {
print("ERROR")
} else if (result?.isCancelled == true) {
print("CANCELLED")
} else if let result = result {
let paymentMethod = result.paymentMethod!.nonce
self.paymentNonce = paymentMethod
self.paymentLabel.text = result.paymentDescription
print(result.paymentIcon)
}
controller.dismiss(animated: true, completion: nil)
}
self.present(dropIn!, animated: true, completion: nil)
}
在用户选择特定付款方式后,我想做的是在屏幕上同时显示说明(“ XX结尾”)和卡的图标。我的描述没有问题,但是我不知道如何显示卡片图标。
以下行:
print(result.paymentIcon)
返回以下内容:
<BTUIKMasterCardVectorArtView: 0x7fd04ad15280; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x600000230c20>>
根据文档,result.paymentIcon是一个UIView。
@property(readonly, nonatomic) UIView *_Nonnull paymentIcon;
A UIView (BTUIKPaymentOptionCardView) that represents the payment option
我尝试设置UIView,然后将paymentIcon添加为子视图,但是仍然无法显示它。
let paymentIcon = result.paymentIcon
self.iconView.addSubview(paymentIcon)
答案 0 :(得分:1)
您可以使用BTUIKViewUtil.vectorArtView
方法检索图像并在UIImageView
中显示,如下所示:
let size = CGSize(width: WIDTH_HERE, height: HEIGHT_HERE)
let imageView = UIImageView(frame: CGRect(origin: .zero, size: size))
imageView.image = BTUIKViewUtil.vectorArtView(for: result.paymentOptionType).image(of: size)
示例2 ,使用paymentIcon
视图:
let view = result.paymentIcon as? BTUIKVectorArtView
imageView.image = view?.image(of: size)