当前位置:编程学习 > wap >>

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;
}
补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,