Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel background obscured when UITableViewCell is selected

I have some UILabel inside a UITableViewCell with opaque background color and white text. When this cell is selected, the UILabel's bg color seems to be obscured by the blue bg color of the selected cell. The UILabel text, however, is showing fine. How do I get the background color of the UILabel to show on top of the cell selection color?

enter image description here

like image 293
pixelfreak Avatar asked Jul 04 '11 07:07

pixelfreak


2 Answers

Had this same issue in an multiple selection table view. Try setting the background color for those labels in -layoutSubviews. Worked for me.

like image 108
jdrama418 Avatar answered Oct 13 '22 01:10

jdrama418


Looks like the background color of labels is changed together with the background color of a row (animated). I just subclassed the UILabel and "protected" backgroundColor changes after I set the initial color:

@interface MyLabel : UILabel {
    BOOL isColorLocked;
}
@property (assign, nonatomic) BOOL isColorLocked;
@end

@implementation MyLabel
@synthesize isColorLocked;
- (void)setBackgroundColor:(UIColor *)backgroundColor {
    if (!isColorLocked) {
        super.backgroundColor = backgroundColor;
    }
}
@end
like image 24
lexa Avatar answered Oct 12 '22 23:10

lexa