praks5432
praks5432

Reputation: 7792

Styling existing UITextField

So I have a UITextField in Interface Builder and I'm trying to change the border.

In my initWithNibName method this is what I do -

        self.searchBar.layer.cornerRadius=8.0f;
        NSLog(@"SEARCH BAR : %@", self.searchBar);
        self.searchBar.layer.masksToBounds=YES;
        self.searchBar.layer.borderColor=[[UIColor redColor]CGColor];
        self.searchBar.layer.borderWidth= 1.0f;

This doesn't work because the searchBar is null, which is strange because I'm in the initWithNibName method.

How do I change the border of this textField?

Upvotes: 1

Views: 63

Answers (1)

TotoroTotoro
TotoroTotoro

Reputation: 17622

You're doing it too early. From the UIViewController doc:

The nib file you specify is not loaded right away. It is loaded the first time the view controller’s view is accessed. If you want to perform additional initialization after the nib file is loaded, override the viewDidLoad method and perform your tasks there.

Upvotes: 1

Related Questions