Reputation: 17339
I'd like to change the appearance of disabled textfields, i.e. text and background color - is there an easy and legal way to achieve this?
Upvotes: 7
Views: 8784
Reputation: 714
You could subclass your UITextfield and overwrite the enabled
property like this
- (void)setEnabled:(BOOL)enabled
{
[super setEnabled:enabled];
// Do your customization here, eg:
self.backgroundColor = [UIColor blackColor];
}
Swift version:
override var isEnabled: Bool {
willSet {
backgroundColor = newValue ? UIColor.white : UIColor.black
}
}
Upvotes: 22
Reputation: 1057
As for only appearance, the UITextField
class has a property named disabledBackground
that takes a UIImage
object as the background image when it is disabled. Similarly, the background
property is used for other cases.
Upvotes: 2