首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

UITextField对象的手工创造

2013-03-27 
UITextField对象的手工创建1.UITextField的初始化和设置UITextField *textField [[UITextField alloc] i

UITextField对象的手工创建
1.UITextField的初始化和设置

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 200, 300, 40)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = @"enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
textField.delegate = self;
[self.view addSubview:textField];
[textField release];

2.要实现的Delegate方法,打开或关闭键盘

显示keyboard:
[textField becomeFirstResponder];
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    [textField becomeFirstResponder];
    return YES;
}

隐藏keyboard
[textField resignFirstResponder];

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

热点排行