一、UITextField

(1)初始化UITextField

UITextField* text = [[UITextField alloc] initWithFrame:CGRectMake(10, 50, 300, 30)];

    text.borderStyle = UITextBorderStyleRoundedRect;

    text.autocorrectionType = UITextAutocorrectionTypeYes;

    text.placeholder = @"XXXXXXX";

    text.returnKeyType = UIReturnKeyDone;

    text.clearButtonMode = UITextFieldViewModeWhileEditing;

    [text setBackgroundColor:[UIColor whiteColor]];

    text.delegate = self;

    [self.view addSubview:text];

(2)详细参数解释

borderStyle:文本框的边框风格

autocorrectionType:可以设置是否启动自动提醒更正功能。

placeholder:设置默认的文本显示

returnKeyType:设置键盘完成的按钮

backgroundColor:设置背景颜色

delegate:设置委托

(3)委托方法

 

-(void)textFieldDidBeginEditing:(UITextField *)textField;

//当开始点击textField会调用的方法



-(void)textFieldDidEndEditing:(UITextField *)textField;

//当textField编辑结束时调用的方法

//按下Done按钮的调用方法,我们让键盘消失

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

[textField resignFirstResponder];

return YES;

}

相关文章:

  • 2022-01-22
  • 2021-08-13
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-06-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-01-09
  • 2022-02-01
相关资源
相似解决方案