我已经看过很多这方面的教程,但它们是针对Objective C的。我想在我的应用中实现这个功能,但不知道该怎么做。 任何帮助都很棒!
答案 0 :(得分:1)
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let alert = UIAlertView(title: "Client id", message: "some title", delegate: self, cancelButtonTitle: "ok")
alert.alertViewStyle = .plainTextInput
let textField: UITextField = alert.textField(at: 0)!
textField.delegate = self
alert.show()
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if (textField.text?.characters.count)! < 10
{
return true
}
return false
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}