gpt4 book ai didi

ios - iOS 上 UITextField 验证的更好方法是什么?

转载 作者:搜寻专家 更新时间:2023-11-01 06:11:37 26 4
gpt4 key购买 nike

我必须对在名为 RSFloatInputView 的库中使用的 ui 文本字段进行验证。

这是我的xib

import UIKit
import RSFloatInputView

class TextInputLayout: UIView {

@IBOutlet weak var revealButton: UIButton!
@IBOutlet weak var warningLabel: UILabel!
@IBOutlet weak var rsFloatingView: RSFloatInputView!
var contentView: UIView?

override init(frame: CGRect) {
super.init(frame: frame)
xibSetup()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
xibSetup()
}

func xibSetup() {
contentView = loadViewFromNib()
contentView!.frame = bounds
contentView!.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
addSubview(contentView!)
}

func loadViewFromNib() -> UIView! {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "TextInputLayout", bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
revealButton.tintColor = Color.grayColor()
warningLabel.textColor = UIColor.red

return view
}
}

我想在这个 View Controller 中实现这个,当我点击下一步按钮时

import UIKit
import DLRadioButton

class SecureWalletViewController: UIViewController,UITextFieldDelegate {

@IBOutlet weak var securityPinStackView: UIStackView!
@IBOutlet weak var securityPin: TextInputLayout!
@IBOutlet weak var confirmSecurityPin: TextInputLayout!

@IBAction func onNextButtonTap(_ sender: Any) {

}

func textInputLayout(at index:Int) -> TextInputLayout {
return securityPinStackView.arrangedSubviews[index] as! TextInputLayout
}
}

最佳答案

UITextFieldDelegate 方法使用验证,如下所示:

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
return true
}

或者使用自定义验证函数Here

关于ios - iOS 上 UITextField 验证的更好方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55371596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com