How can I customize all UITextField manifestations to borderWidth?

I am trying to set all UITextField manifestations to borderWith.

Trying something like this. Only the first 2 lines are relevant. The rest of the lines don't work?

[[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;

      

+3


source to share


2 answers


Unfortunately the appearance proxy does not work on layers to do what you want the UITextField subclasses and do your settings in the layoutSubviews method (or in init)



+1


source


You can apply this to a class extended from UITextField

or whatever UIControl

style you like.

1. Created extension

from UITextField

and added the 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 UITextField

inside your code, #import

extend yours UITextField

and create UITextField

.

2.2 Create UITextField in Interface Builder

If you create UIButton

inside Interface Builder

, select UITextField

, go to Identity Inspector

and add the created extension

as class

for UITextField

.

+5


source







All Articles