I need to override the setter of UIViews highlighted property in my custom UIButton subclass ;
Objective C
@property(nonatomic,getter=isHighlighted) BOOL highlighted;
overridden like this
- (void) setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
if (highlighted) {
self.backgroundColor = UIColorFromRGB(0x387038);
}
else {
self.backgroundColor = UIColorFromRGB(0x5bb75b);
}
[super setHighlighted:highlighted];
}
Swift
var highlighted: Bool
I tried:
var highlighted: Bool {
get{ return false }
set {
if highlighted {
self.backgroundColor = UIColor.whiteColor()
//Error "Use unresolved identifier 'self'"
I can't set the background color from value type in here
, can't call self.backgroundColor in this value type ,
can't call super too because this is a value type , doesn't work
}
}
}
How and where should implement this method in Swift to get the same result . any idea?