Lord Vermillion
Lord Vermillion

Reputation: 5424

What method is called when UITextField is rendered

I want to make a subclass of UITextField that change the style of it automatically.

I tried to subclass and override the init method:

- (id)init
{
    self = [super init];
    if (self) {
        self.layer.borderWidth = 1.0;
        self.layer.borderColor = [[StyleKit2 blue]CGColor];
        self.layer.cornerRadius = 5.0;
    }
    return self;
}

Then i set this as the custom class in storyboard.

But it does not effect the textview.

Upvotes: 0

Views: 54

Answers (2)

Miknash
Miknash

Reputation: 7948

You can put the same code in awakeFromNib:

-(void)awakeFromNib
{
    [super awakeFromNib]; 

    self.textFieldx.layer.borderWidth =1.0;
    self.layer.borderColor = [[StyleKit2 blue]CGColor];
    self.layer.cornerRadius = 5.0;

}

You can try to override it in initWithFrame as well.

You can add these attributes in Interface builder in user defined runtime attributes(third tab), except the color. In interface builder you can set UIColor but you need CGColor for borderColor.

Upvotes: 1

Related Questions