我将 UIControl 子类化以创建自己的类。我正在尝试覆盖setHighligheted:
,但由于某种原因它没有被调用......我已经仔细检查过,我的子视图都没有userInteractionEnabled = NO
. 还有其他我应该覆盖的方法吗?
谢谢!
这是一些示例代码:
#import "Booking.h"
@interface BookingCloud : UIControl
// Booking
@property(nonatomic, strong) Booking *booking;
// BackgroundView
@property (strong, nonatomic) IBOutlet UIView *backgroundView;
以及实施
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setUpSubViews];
}
return self;
}
- (void)setUpSubViews {
[[NSBundle mainBundle] loadNibNamed:@"BookingCloud" owner:self options:nil];
[self addSubview:backgroundView];
self.frame = backgroundView.frame;
self.layer.cornerRadius = 10;
self.layer.masksToBounds = YES;
}
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
if (highlighted) {
backgroundView.backgroundColor = [[Utils colorWithHexString:[[ConfigurationManager instance] UIConfigValueForKey:@"background_color"]] colorWithAlphaComponent:0.8];
} else {
backgroundView.backgroundColor = [[Utils colorWithHexString:[[ConfigurationManager instance] UIConfigValueForKey:@"background_color"]] colorWithAlphaComponent:1];
}
}