开发者

UITextView highlightedTextColor or similar option?

开发者 https://www.devze.com 2022-12-17 16:55 出处:网络
I have a custom UITableViewCell with a UILabel and a UITextView in it. I want the text for both of these to appear white when the user h开发者_如何学Goighlights the UITableViewCell. It\'s obviously

I have a custom UITableViewCell with a UILabel and a UITextView in it.

I want the text for both of these to appear white when the user h开发者_如何学Goighlights the UITableViewCell. It's obviously very simple to set the highlightedTextColor of the UILabel, but the UITextView doesn't seem to have any similar type of property. Am I going to have to manually change the color of the UITextView whenever the cell becomes highlighted/unhighlighted or is there an easier way of accomplishing this?

Thanks!


Found it and it was a lot easier than I thought. Just need to use the UITableViewCell setHighlighted method.

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];

    if (highlighted) {
        [self.myTextView setTextColor:[UIColor whiteColor]];
    } else {
        [self.myTextView setTextColor:[UIColor blackColor]]; 
    }

}


The solution posted by the author is half right for my situation. Need to keep in mind that the following events happen:

  1. press down --> setHighlighted:YES animated: is called
  2. press up --> setHighlighted:NO animated is called
  3. set selection --> setSelected:YES animated is called

Knowing this, and depending on how you want the TableCell to look when highighted vs when selected will determine if you need to implement setHighlighted:animated:, setSelected:animated: or both methods.

For the look I want, I need to implement both methods.

0

精彩评论

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

关注公众号