1. 首先在.h裡先宣告
UITextField *usrname;
@property (nonatomic, retain, readonly) UITextField usrname;
在.m裡面
@synthesize usrname;
2. 然後自己加上
- (UITextField *)usrname
{
if (usrname == nil)
{
CGRect frame = CGRectMake(x, y, width, height);
usrname = [[UITextField alloc] initWithFrame:frame];
usrname.borderStyle = UITextBorderStyleNone;
usrname.textColor = [UIColor blackColor];
usrname.font = [UIFont systemFontOfSize:17.0];
usrname.placeholder = @"user name";
usrname.backgroundColor = [UIColor whiteColor];
usrname.autocorrectionType = UITextAutocorrectionTypeNo;
usrname.autocapitalizationType = UITextAutocapitalizationTypeNone;
usrname.keyboardType = UIKeyboardTypeDefault;
usrname.returnKeyType = UIReturnKeyDone;
usrname.clearButtonMode = UITextFieldViewModeWhileEditing;
//we can remove it later for recycled cells
usrname.tag = kViewTag;
//when the keyboard's "Done" button is pressed
usrname.delegate = self;
// Add an accessibility label that describes what the text field is for.
usrname setAccessibilityLabel:NSLocalizedString(@"username", @"")];
}
return usrname;
}
喔~最後要在dealloc中release
[usrname release];
這篇文章也可以在CocoaChina找到
沒有留言:
張貼留言