Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set border style of a UITextfield

How can I set the border style of a UITextField programatically?

I am creating my text field like so:

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; [self.view addSubview:tfText]; [tfText release]; 
like image 364
Kiran Avatar asked Apr 26 '11 11:04

Kiran


People also ask

How do you add a border color in Swift?

You need to set the borderWidth from the UITextField 's layer property. Like: email. layer. borderWidth = 1 .

How do you color border TextField?

You can change the TextField border color globally by defining the inputDecorationTheme and then adding the OutlineInputBorder widget. Inside the OutlineInputBorder widget, you can specify which type of border you want to change. for example, enabledBorder , focusedBorder , and so on, and then assign the color.


2 Answers

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/
like image 193
Chetan Bhalara Avatar answered Sep 22 '22 02:09

Chetan Bhalara


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.

like image 23
pasine Avatar answered Sep 20 '22 02:09

pasine