iOS : Add a UIView returned by Braintree to the screen

标签 ios swift braintree

我按照 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 添加为 subview ,但仍然无法显示它。

let paymentIcon = result.paymentIcon
self.iconView.addSubview(paymentIcon)

最佳答案

您可以使用 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 View :

let view = result.paymentIcon as? BTUIKVectorArtView
imageView.image = view?.image(of: size)

关于iOS : Add a UIView returned by Braintree to the screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51827035/

相关文章:

ios - 为什么 locationManager didUpdateLocation 不工作?

ios - CryptoKit 在 iOS 版本低于 13 的手机上抓取应用程序

ios - 如何对复选框按钮进行 UI 测试

ios - 接收 EXC_BAD_ACCESS 异常

ruby-on-rails - (Rails) Paypal 支付与 Braintree v.zero SDK

ios - UITabBarController - 子(选项卡)ViewControllers 的不正确和不一致的边界

ios - 我应该在关闭 View 之前关闭键盘吗?

ios - 如何正确更新自定义类属性?

braintree - 从 Braintree 的 dropin ui 中隐藏 paypal 按钮

javascript - 如何在单击 braintree PayPal 结帐按钮时验证自定义表单?