Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How may i customise all UITextField appearances for borderWidth?

i am trying to customise all UITextField appearances for borderWith.

Trying something like this. Only first 2 lines are making a difference. Rest of the lines not working ?

[[UITextField appearance] setBackgroundColor:[UIColor greenColor]];
[[UITextField appearance] setTextColor:[UIColor blackColor]];
[UITextField appearance].layer.cornerRadius = 6.0f;
[UITextField appearance].layer.borderColor = [UIColor redColor].CGColor;
[UITextField appearance].layer.borderWidth = 3.f;
like image 214
Add080bbA Avatar asked Feb 12 '23 09:02

Add080bbA


1 Answers

You can apply this to a class extended from UITextField or any UIControl you like to style.

1. Created an extension of UITextField and added following code:

- (void)awakeFromNib{

    self.layer.borderColor = [UIColor blueColor].CGColor;
    self.layer.borderWidth = 1.0f;
}

2.1 Create UITextField inside Code

Now if you create a UITextField inside your code, #import the extension of your UITextField and create the UITextField.

2.2 Create UITextField in Interface Builder

If you create the UIButton inside the Interface Builder, select the UITextField, go to the Identity Inspector and add the created extension as class for the UITextField.

like image 113
Alex Cio Avatar answered Apr 30 '23 19:04

Alex Cio