开发者

Change label property when cell selected

开发者 https://www.devze.com 2022-12-17 18:43 出处:网络
I am using a custom cell with multiple labels contained in it. I would like to change the text color of all labels to white, when the cell is selected. How would do this?

I am using a custom cell with multiple labels contained in it. I would like to change the text color of all labels to white, when the cell is selected. How would do this?

Appreciate an开发者_JAVA技巧y help.


Set the labels' highlightColor property to white.


In the implementation of the custom cell class overwrite the following method

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
     [super setSelected:(BOOL)selected animated:(BOOL)animated];
     [someLabel setTextColor:[UIColor whiteColor]];
}


either set the highlighted/selected color(code or ib) or do what the above poster suggested except you need to put it inside an if statement since that code sets the text even if the cells get sent a deselected value

eg..

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
     [super setSelected:(BOOL)selected animated:(BOOL)animated];
     if (selected) {
           [someLabel setTextColor:[UIColor whiteColor]];
     }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消