how to set border style of a UITextfield

Try this

UITextField *tfText = [[UITextField alloc] initWithFrame:CGRectMake(65, 200, 200, 30)];
tfText.backgroundColor = [UIColor colorWithRed:0.2 green:0.9 blue:0.5 alpha:0.3];       
tfText.textAlignment = UITextAlignmentCenter;
// Border Style None
[tfText setBorderStyle:UITextBorderStyleNone];
[self.view addSubview:tfText];
[tfText release];

For Reference

  • http://www.icodeblog.com/2010/01/04/uitextfield-a-complete-api-overview/

You can use Quartzcore and the layer properties.

sometextfield.layer.borderWidth = 1;
sometextfield.layer.borderColor = [[UIColor redColor] CGColor];

I must remember to add QuartzCore to your project and to import it where you want to use it.


From below four, anyone can be used programatically,

[textField setBorderStyle:UITextBorderStyleNone];

[textField setBorderStyle:UITextBorderStyleLine];

[textField setBorderStyle:UITextBorderStyleBezel];

[textField setBorderStyle:UITextBorderStyleRoundedRect];

where textField is an outlet of UITextField