textField的创建
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 180, 30)];
self.textField.backgroundColor = [UIColor whiteColor];
self.textField.layer.cornerRadius = 8;
self.textField.layer.borderColor = [[UIColor lightGrayColor]CGColor];
// 设置textField内容
self.textField.text = @"123";
self.textField.placeholder = @" 请输入信息";
[self.view addSubview:self.textField];
[self.textField release];
self.textField.delegate = self;
textField的一些独特属性
// 把输入内容以圆点显示
self.textField.secureTextEntry = YES;
// 修改return键的样式
self.textField.returnKeyType = UIReturnKeyDone;
// 清除按钮
self.textField.clearButtonMode = UITextFieldViewModeAlways;
textField的协议(UITextFieldDelegate)
// 开始编辑时触发
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
// 已经开始编辑时触发
- (void)textFieldDidBeginEditing:(UITextField *)textField;
// 结束时触发
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;
// 已经结束时触发
- (void)textFieldDidEndEditing:(UITextField *)textField;
// 实时监控输入内容, 但输出比当前输入内容少一位,textField.text和string拼接起来才是当前textField中的内容
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;