不调用UIControl子类setHighlighted

时间:2013-03-17 14:19:19

标签: ios subclass highlight uicontrol

我已经将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];
    }

}

0 个答案:

没有答案