Swift:条纹付款界面无法在SwiftUI中正确显示

时间:2020-11-04 14:48:38

标签: uiviewcontroller swiftui stripe-payments

我正在尝试在SwiftUI中显示ViewController类的Stripe Payment UI,但是UI不能正确显示

import SwiftUI
import UIKit
import Stripe
import Alamofire


class CheckoutViewController: UIViewController {
   var setupIntentClientSecret: String?

     lazy var cardTextField: STPPaymentCardTextField = {
     let cardTextField = STPPaymentCardTextField()
     return cardTextField
       }()
   lazy var payButton: UIButton = {
      let button = UIButton(type: .custom)
       button.layer.cornerRadius = 5
       button.backgroundColor = .systemBlue
       button.titleLabel?.font = UIFont.systemFont(ofSize: 22)
       button.setTitle("Save", for: .normal)
       button.addTarget(self, action: #selector(pay), for: .touchUpInside)
      return button
   }()
lazy var emailTextField: UITextField = {
    let emailTextField = UITextField()
    emailTextField.placeholder = "Enter your email"
    emailTextField.borderStyle = .roundedRect
    return emailTextField
}()
lazy var mandateLabel: UILabel = {
    let mandateLabel = UILabel()
    mandateLabel.text = "I authorise Stripe Samples to send instructions to the financial institution that issued my card to take payments from my card account in accordance with the terms of my agreement with you."
    mandateLabel.numberOfLines = 0
    mandateLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
    mandateLabel.textColor = .systemGray
    return mandateLabel
}()

override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .white
    let stackView = UIStackView(arrangedSubviews: [emailTextField, cardTextField, payButton, mandateLabel])
    stackView.axis = .vertical
    stackView.spacing = 20
    stackView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(stackView)
    NSLayoutConstraint.activate([
        stackView.leftAnchor.constraint(equalToSystemSpacingAfter: view.leftAnchor, multiplier: 2),
        view.rightAnchor.constraint(equalToSystemSpacingAfter: stackView.rightAnchor, multiplier: 2),
        stackView.topAnchor.constraint(equalToSystemSpacingBelow: view.topAnchor, multiplier: 2),
    ])
    
    HandlePayment().startCheckout()
}
}

我试图使用此将Viewcontroller转换为SwifUI

struct CheckoutViewControllerWrapper: UIViewControllerRepresentable {

  typealias UIViewControllerType = CheckoutViewController

  func makeUIViewController(context: UIViewControllerRepresentableContext<CheckoutViewControllerWrapper>) -> CheckoutViewControllerWrapper.UIViewControllerType {
    return CheckoutViewController()
 }
func updateUIViewController(_ uiViewController: CheckoutViewControllerWrapper.UIViewControllerType, context: UIViewControllerRepresentableContext<CheckoutViewControllerWrapper>) {
   
} }

,然后在SwiftUI中以此调用UI

 LCButton(text: "Add Payment") {

           self.showPaymentSheet = true
         }
                    
        .sheet(isPresented: $showPaymentSheet) {
            CheckoutViewControllerWrapper()
        }

这是显示的内容 ui

缺少什么,我不确定为什么UI不会显示为标准的条带集成UI

0 个答案:

没有答案