尝试将Paystack与我的应用集成。使用PSTCKPaymentCardTextField,如guide中所述,但在我运行应用程序时,它在我的视图中不会显示任何内容。
import UIKit
import Paystack
class PaymentViewController: UIViewController, PSTCKPaymentCardTextFieldDelegate {
let paymentTextField: PSTCKPaymentCardTextField = {
let ptf = PSTCKPaymentCardTextField()
return ptf
}()
func setupPaymentTextField() {
let paymentFormWidth = self.view.frame.width - 30
paymentTextField.frame = CGRect(x: 15, y: 15, width: paymentFormWidth, height: 44)
paymentTextField.delegate = self
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
view.addSubview(paymentTextField)
setupPaymentTextField()
}
}
我做错了吗?请帮帮我。 感谢
注意:我是swift语言的新手
答案 0 :(得分:0)
问题解决了!使用自动布局而不是使用paymentTextField.frame = CGRect(x: 15, y: 15, width: paymentFormWidth, height: 44)
func setupPaymentTextField() {
paymentTextField.delegate = self
paymentTextField.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
paymentTextField.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
paymentTextField.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -30).isActive = true
paymentTextField.heightAnchor.constraint(equalToConstant: 45).isActive = true
}