Codesnipp.it Social Code Sharing

Scott Rapson

Create UITextField pragmatically

by Scott Rapson on Feb 18, 2011

//in the header //in the @interface {} IBOutlet UITextField *userName; //under the @interface {} @property(nonatomic, retain) IBOutlet UITextField *userName; //in the method. Corner radius requires quartzcore framework // Make the UITextField with given properties userName = [[UITextField alloc] initWithFrame:CGRectMake(70, 220, 180, 30)]; userName.delegate = self; userName.placeholder = @"placeholder"; //formatting for the UITextField (border and stuff) userName.textAlignment = UITextAlignmentCenter; //text alignment userName.borderStyle = UITextBorderStyleRoundedRect; //border style [userName.layer setBackgroundColor: [[UIColor whiteColor] CGColor]]; //background colour [userName.layer setBorderColor: [[UIColor grayColor] CGColor]]; //border colour [userName.layer setBorderWidth: 1.0]; //border width [userName.layer setCornerRadius: 4.0f]; //corner radius [userName.layer setMasksToBounds: YES]; //bounding box //more important settings userName.autocorrectionType = UITextAutocorrectionTypeNo; //autocorrect toggle userName.keyboardType = UIKeyboardTypeDefault; //keyboard type userName.returnKeyType = UIReturnKeyDone; //make the return key read DONE instead of return [self.view addSubview: userName]; [userName release]; //end the textfield settings

Can't see the comments? Please login first :)