美文网首页
UITableViewCell选中后子View背景色改变

UITableViewCell选中后子View背景色改变

作者: 观星 | 来源:发表于2016-03-17 09:19 被阅读454次

自定义了UITableViewCell,设置自己添加的label的backgroundColor为紫色,但是当Cell被选中的时候,lable的backgroundColor被改变了。观察一下label的backgroundColor在cell选中时的变化。

 [RACObserve(self.lblSimple, backgroundColor) subscribeNext:^(id x) {
   
    NSLog(@"%@",x);
}];

输出结果为

UIDeviceWhiteColorSpace 0 0
UIDeviceRGBColorSpace 0.541 0.761 0.953 1
UIDeviceRGBColorSpace 0.541 0.761 0.953 1
UIDeviceWhiteColorSpace 0 0
UIDeviceRGBColorSpace 0.541 0.761 0.953 1     
UIDeviceRGBColorSpace 0.541 0.761 0.953 1

这和cell的

- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated ;   

密切相关。看看文档,下面是

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated ;   

方法的文档

Sets the highlighted state of the cell, optionally animating the transition 
between states.
    Highlights or unhighlights the cell, animating the transition between 
regular and highlighted state if animated is YES. Highlighting affects the 
appearance of the cell’s labels, image, and background.
    Note that for highlighting to work properly, you must fetch the cell’s 
label (or labels) using the textLabel (and detailTextLabel properties and set 
the label’s highlightedTextColor property; for images, get the cell’s image
 using the imageView property and set the UIImageView object’s
 highlightedImage property.
    A custom table cell may override this method to make any transitory 
appearance changes.

注意

Highlighting affects the appearance of the cell’s labels, image, and background.

另外一个方法

- (void)setSelected:(BOOL)selected animated:(BOOL)animated;

也差不多。
但个人感觉选中时cell的表现还和tableView的allowsSelection,allowsMultipleSelection,allowsSelectionDuringEditing,allowsMultipleSelectionDuringEditing,editting等属性相关,cell自身的selectionStyle的影响自是不必说。具体测试代码,有时间再补上。

相关文章

网友评论

      本文标题:UITableViewCell选中后子View背景色改变

      本文链接:https://www.haomeiwen.com/subject/kalqlttx.html