classViewController:UIViewController,UITextFieldDelegate{
overridefuncviewDidLoad() {
super.viewDidLoad()
lettextField =UITextField.init(frame:CGRect(x:10, y:60, width:200, height:20))
textField.borderStyle=UITextBorderStyle.roundedRect
textField.placeholder="請(qǐng)輸入用戶名"
textField.adjustsFontSizeToFitWidth=true//當(dāng)文字超出文本框?qū)挾葧r(shí),自動(dòng)調(diào)整文字大小
textField.minimumFontSize=14//最小可縮小的字號(hào)
textField.textAlignment= .right//水平右對(duì)齊
textField.delegate=self
/**水平對(duì)齊
textField.textAlignment = .center //水平居中對(duì)齊
textField.textAlignment = .left //水平左對(duì)齊
**/
/**垂直對(duì)齊
textField.contentVerticalAlignment = .top//垂直向上對(duì)齊
textField.contentVerticalAlignment = .center//垂直居中對(duì)齊
textField.contentVerticalAlignment = .bottom//垂直向下對(duì)齊
**/
textField.clearButtonMode= .whileEditing//編輯時(shí)出現(xiàn)清除按鈕
/*
textField.clearButtonMode = .unlessEditing//編輯時(shí)不出現(xiàn),編輯后才出現(xiàn)清除按鈕
textField.clearButtonMode = .always//一直顯示清除按鈕
*/
textField.returnKeyType=UIReturnKeyType.go
/*
textField.returnKeyType = UIReturnKeyType.done //表示完成輸入
textField.returnKeyType = UIReturnKeyType.go //表示完成輸入溅漾,同時(shí)會(huì)跳到另一頁(yè)
textField.returnKeyType = UIReturnKeyType.search //表示搜索
textField.returnKeyType = UIReturnKeyType.join //表示注冊(cè)用戶或添加數(shù)據(jù)
textField.returnKeyType = UIReturnKeyType.next //表示繼續(xù)下一步
textField.returnKeyType = UIReturnKeyType.send //表示發(fā)送
*/
self.view.addSubview(textField)
}
functextFieldShouldReturn(_textField:UITextField) ->Bool{
//收起鍵盤(pán)
textField.resignFirstResponder()
//打印出文本框中的值
print(textField.text??"沒(méi)有")
returntrue;
}
overridefuncdidReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}