WEB开发网
开发学院手机开发iPhone 开发 iPhone App里弹出输入面板的方法 阅读

iPhone App里弹出输入面板的方法

 2010-06-19 18:34:00 来源:WEB开发网   
核心提示:在.h里先宣告UITextField *yourtextfield;@property (nonatomic, retain, readonly) UITextField yourtextfield;在.m里@synthesize yourtextfield;然后自己加上- (UITextField *)yourtex

在.h里先宣告

UITextField *yourtextfield;

@property (nonatomic, retain, readonly) UITextField yourtextfield;

在.m里

@synthesize yourtextfield;

然后自己加上

- (UITextField *)yourtextfield

{

if (yourtextfield == nil)

{

CGRect frame = CGRectMake(x, y, width, height); //textfield的位置大小

yourtextfield = [[UITextField alloc] initWithFrame:frame];

yourtextfield.enabled = TRUE;

yourtextfield.borderStyle = UITextBorderStyleNone;

yourtextfield.textColor = [UIColor blackColor];

yourtextfield.font = [UIFont systemFontOfSize:14.0];

yourtextfield.placeholder = @"user name";

yourtextfield.backgroundColor = [UIColor whiteColor];

yourtextfield.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support

yourtextfield.keyboardType = UIKeyboardTypeDefault; // 一般的键盘style

yourtextfield.returnKeyType = UIReturnKeyDone;

yourtextfield.clearButtonMode = UITextFieldViewModeWhileEditing; //可以一次清除输入中的文字

yourtextfield.tag = kViewTag; // tag this control so we can remove it later for recycled cells

textFieldNormalyourtextfield.delegate = self; // 让user输入完,按下done 键盘会自动收起来

// Add an accessibility label that describes what the text field is for.

[yourtextfield setAccessibilityLabel:NSLocalizedString(@"username", @"")];

}

return yourtextfield;

}

最后要在dealloc 中release

[yourtextfield release];

Tags:iPhone App 输入

编辑录入:coldstar [复制链接] [打 印]
赞助商链接