Xcode9学习笔记27 - 文本输入框控件的使用UITextField
2017-11-04 07:42
507 查看
//添加文本框代理协议UITextFieldDelegate,使用协议中的方法,在完成文本框文字的输入后,隐藏系统键盘的显示
class ViewController: UIViewController,UITextFieldDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let rect = CGRect(x: 60, y: 80, width: 200, height: 30)
let textField = UITextField(frame: rect)//初始化文本输入框对象,设置位置、尺寸属性
textField.borderStyle = UITextBorderStyle.roundedRect//设置文本框对象的边框样式为圆角矩形
textField.placeholder = "Your Email"//设置文本框的占位符属性
textField.autocorrectionType = UITextAutocorrectionType.no//关闭文本框对象的语法错误提示功能
textField.returnKeyType = UIReturnKeyType.done//设置在文字输入时,在键盘面板上,回车按钮的类型
textField.clearButtonMode = UITextFieldViewMode.whileEditing//设置文本框对象右侧的清除按钮,仅在编辑状态时显示
textField.keyboardType = UIKeyboardType.emailAddress//设置文本框对象的键盘类型
textField.keyboardAppearance = UIKeyboardAppearance.dark//设置文本框对象的键盘为暗色主题
textField.delegate = self//设置文本框对象的代理为当前视图控制器
self.view.addSubview(textField)//将文本框对象添加到当前视图控制器的根视图
}
//添加一个代理方法,当用户按下键盘上的回车键时,调用此方法
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()//当用户按下键盘上的回车键时,文本框对象失去焦点,键盘也将自动隐藏
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
相关文章推荐
- iOS学习总结之UI框架UI之文本输入控件( UITextField)
- IOS 学习笔记(6) 控件 文本域(UITextField)的使用方法
- Silverlight学习笔记(五):文本编辑控件的使用
- Xcode9学习笔记22 - UIButton控件的使用(边框、圆角、背景色、标题、类型)
- 我的iphone开发学习笔记(二)使用UITextView, UITextField 和UIButton控件
- IOS 学习笔记(5) 控件 文本视图(UITextView)的使用方法
- IOS学习笔记 ­­­­­­— UITextField 输入完毕关闭键盘方法
- 王爽《汇编语言》(第二版) 学习笔记 (第十七章 使用BIOS进行键盘输入和磁盘读写)
- IOS学习笔记27—使用GDataXML解析XML文档
- 学习笔记:Tab Bar 控件使用详解
- IOS学习笔记27—使用GDataXML解析XML文档
- Flex权威指南3学习笔记之二------简单控件的使用
- SilverLight学习笔记--Silverlight中GridSplitter控件的使用
- IOS学习笔记27—使用GDataXML解析XML文档
- 学习笔记之使用vi之文本操作(四)
- j2me学习笔记【15】——使用低层用户界面显示文本小实例
- Java学习笔记27:模板Velocity使用方法
- C#中使用Property Grid 控件 学习笔记(一)
- 学习笔记之使用vi之文本操作(五)
- 汇编语言学习笔记-使用窗体控件