Reputation: 5424
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
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
Reputation: 1564
Try These links How to write a Custom UItextField Class , iOS - Implementing a Class for UITextField , http://pivotallabs.com/iphone-on-blocks-uitextfields/.
Upvotes: 0