1

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];
    }

}
4

0 に答える 0