- UITextField
- http://www.tuicool.com/articles/a6R3eq
- 默認(rèn)情況下,當(dāng)向textField輸入文字時,文字會緊貼在textField左邊框上.我們可以通過設(shè)置textField的leftView,設(shè)置一個只有寬度的leftView.這樣還不夠,因為默認(rèn)leftView是不顯示的.還需要將leftViewMode設(shè)置為UITextFieldViewModeAlways.這樣就完成了. (小技巧:通過查詢UITextField的頭文件可以看出leftView和leftViewMode這兩個屬性寫在了一組,與其他屬性之間是分開的,說明這兩個屬性的關(guān)系很緊密)
//設(shè)置文本框左邊的view
UITextField *textField = [[UITextField alloc]init];
textField.frame = CGRectMake(10, 30, 300, 30);
[self.view addSubview:textField];
textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 0)];
//設(shè)置顯示模式為永遠(yuǎn)顯示(默認(rèn)不顯示)
textField.leftViewMode = UITextFieldViewModeAlways;
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者