I am planning to subclass UITextField so I can customise the look and feel of textfields in my app globally. Based on the design in our mockups, textfields should have a green border which I already did for one of my textfields. (source: https://stackoverflow.com/a/5749376/334545)
I also changed placeholder color as said here: https://stackoverflow.com/a/19852763/334545
But all these are for just one textfield. I want all of my other textfields to have this so I tried subclassing by creating a new uitextfield class which I tried using. I added the methods above to MYUITextField.m
's initWithFrame method:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
UIColor *greenColor = [UIColor colorWithRed:122.0/255.0 green:168.0/255.0 blue:73.0/255.0 alpha:1.0];
UIColor *greyColor = [UIColor colorWithRed:87.0/255.0 green:87.0/255.0 blue:87.0/255.0 alpha:1.0];
self.layer.borderColor=[greenColor CGColor];
self.layer.borderWidth= 1.0f;
self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName: greyColor}];
}
return self;
}
Should I just change the drawRect method? Will the app be slower because of it?