I have a custom UITableViewCell
, with an UILabel
and an UIImageView
. I want to change the background color and the text color when the cell is highlighted. In my CustomCell
's setHighlighted
method, I have the following piece of code:
-(void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
if(self) {
if(highlighted) {
self.title.textColor = [UIColor whiteColor];
} else {
self.title.textColor = [UIColor blackColor];
}
//highlight background
UIView *bgColorView = [[UIView alloc] initWithFrame:self.frame];
bgColorView.backgroundColor = [UIColor blackColor];
[self setSelectedBackgroundView:bgColorView];
}
}
I already tried to put the code for textColor
change in the tableView
's didSelectRowAtIndexPath
, but it's not the effect that I want - I want the text color to change when the user touches down on the cell - not at touch up.
Any suggestions?
You should use the attribute highlightedTextColor
. Set the color for the cell inside tableView:cellForRowAtIndexPath
and it should look like this:
cell.textLabel.highlightedTextColor = [UIColor blueColor];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With