UITextField详解

一、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;

}
posted @ 2012-08-01 18:19  奔放小青年  阅读(551)  评论(0编辑  收藏  举报