I subclassed UIButton
in my app and there are many times when the highlight color stays even when I'm done pressing down the button. I can't figure out exactly what causes this since it only seems to happen by chance, but it seems to happen about 50% of the time. I'm very sure that this is reproducible. I often get this to happen when I have a button in a UITableViewCell
and I click on it while the table view is still scrolling.
Is there something wrong with the way I'm overriding the setHighlighted
method in the subclass? This is my implementation:
@implementation SCPFormButton
- (id)initWithFrame:(CGRect)frame label:(NSString *)label
{
self = [super initWithFrame:frame];
if (self) {
UILabel *buttonLabel = [[UILabel alloc] init];
buttonLabel.attributedText = [[NSAttributedString alloc] initWithString:[label uppercaseString] attributes:kButtonLabelAttributes];
[buttonLabel sizeToFit];
buttonLabel.frame = CGRectMake(kMaxWidth / 2 - buttonLabel.frame.size.width / 2, kStandardComponentHeight / 2 - buttonLabel.frame.size.height / 2, buttonLabel.frame.size.width, buttonLabel.frame.size.height);
[self addSubview:buttonLabel];
self.backgroundColor = kFormButtonColorDefault;
}
return self;
}
- (void)setHighlighted:(BOOL)highlighted
{
self.backgroundColor = highlighted ? kFormButtonColorHighlighted : kFormButtonColorDefault;
[self setNeedsDisplay];
}
@end