修改点击cell时显示的颜色

 首先清楚一点, 当咱们点击cell的时候, 会默认是蓝色的效果atom

@property(nonatomic,getter=isSelected) BOOL         selected;   // 是否被选中spa

若是是YES, 选中cell的时候, cell会变成蓝色, 让用户知道被选中了图片

若是是NO, 点击cell手指不离开, cell仍是会显示蓝色, 当手指离开后, 蓝色消失get

有时候cell只是起到展现信息的做用,并无跳转页面之类的, 显然若是将selected=NO仍是有些不满意, 由于cell在点击的时候仍是会有变化, 如何设置一下, 让用户点击cell一点反应都没有呢it

@property(nonatomicUITableViewCellSelectionStyle  selectionStyle;           // default is UITableViewCellSelectionStyleBlue.io

 

看到这里, 咱们笑了, 原来点击的那个蓝色效果就是这里出来的, 看看还有些其余能够选择的table

    UITableViewCellSelectionStyleNone,select

    UITableViewCellSelectionStyleBlue,  //default margin

    UITableViewCellSelectionStyleGraytop

显然UITableViewCellSelectionStyleNone这个属性就是咱们想要的了

 

这个属性提供了2种颜色, 默认的蓝色和灰色, 但这远远不够, 因此咱们须要自定义选中cell时的颜色

@property(nonatomic,retainUIView   *selectedBackgroundView;

看看这个属性, 就知道是什么了

cell.contentView.backgroundColor = [UIColor clearColor];

UIView *aView = [[UIView allocinitWithFrame:cell.contentView.frame];

aView.backgroundColor = [UIColor redColor];

self.selectedBackgroundView = aView;   设置选中后cell的背景颜色

[aView release];<p>

 

这里举例这是单纯的设置颜色,  其实能够有不少花样

selectedBackgroundView是View类型, 咱们能够用UIImageView也行, 在嵌套图片, 效果能够作的更好

 

同理如何来设置cell的背景颜色呢(跟点击cell没有关系)

须要说明一点的是:

若是tableView是plain类型, 那么cell的背景颜色就是tableView的背景颜色, 就算设置了cell.backgroundColor貌似也没用

若是tableView是group类型, cell的背景颜色跟tableView的背景无关, 须要单独在设置cell.backgroundColor

@property(nonatomic,retainUIView                *backgroundView;

看这个属性就知道了, 至于如何设置跟上面相同

相关文章
相关标签/搜索