UIKit學習之UITextField的用法
ide
UITextField的建立:學習
(1) 在Stroyboard中使用Ctrl+Drag拖拽法建立spa
(2) 代碼建立code
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. //建立一個TextField控件 let myTextField = UITextField(frame: CGRectMake(10,260,200,30)) //設置邊框樣式爲圓角矩形 myTextField.borderStyle = UITextBorderStyle.RoundedRect //文本框提示文字 myTextField.placeholder="請輸入用戶名" //設置文本框的清除按鈕 (輸入框內右側小叉) myTextField.clearButtonMode = UITextFieldViewMode.WhileEditing myTextField.becomeFirstResponder() //myTextField.resignfirstresponder() //設置鍵盤return鍵的樣式 myTextField.returnKeyType = UIReturnKeyType.Next self.view.addSubview(myTextField) }
參考資料:orm