博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UITableView点击背景
阅读量:7180 次
发布时间:2019-06-29

本文共 1315 字,大约阅读时间需要 4 分钟。

系统自定义的点击背景有时间觉得效果不好想换个

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {    [super setSelected:selected animated:animated];    if (selected) {        self.backgroundColor = [UIColor redColor];    }else {        self.backgroundColor = [UIColor whiteColor];    }}

如果你发现时上面的,0-0那肯定没成功啊,为什么呢?

打开层级,可以看到,原来在下面,这样就简单了,只需要在初始化cell后加上这么一段代码

cell.selectionStyle = UITableViewCellSelectionStyleNone;

效果图:

-0-成功了~~~~~~~~~~~~~~~~~~~

 add...

如果想实现闪一下而不是一直选择的话,可以用tablview的代理实现

首先:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {    [super setSelected:selected animated:animated];    if (selected) {      self.backgroundColor = [UIColor whiteColor];    }else {        self.backgroundColor = [UIColor whiteColor];    }}

在tablview的代理中:

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];    cell.backgroundColor = [UIColor greenColor];}

效果图:

so-简单方法,自定义cell里面,可以实现一样的效果,也不用在外面写了

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {    [super setHighlighted:highlighted animated:animated];    if (highlighted) {        self.backgroundColor = [UIColor redColor];    }else {        self.backgroundColor = [UIColor whiteColor];    }}

 

转载于:https://www.cnblogs.com/hxwj/p/4731959.html

你可能感兴趣的文章
WCF 4.0 进阶系列 – 第十五章 构建REST服务(第二部分)
查看>>
MySQL5.7: datetime
查看>>
Virtualenv教程
查看>>
2011年8月11日星期四
查看>>
艾伟也谈项目管理,项目管理实战之团队管理
查看>>
IE9是最佳浏览器?
查看>>
快速把web项目部署到weblogic上
查看>>
objcopy
查看>>
RGB_YUV_YCbCr
查看>>
虚拟内存机制
查看>>
一个CSV文件解析类
查看>>
javascript调用C#后台程序执行查询
查看>>
使用MonoTouch进行iOS开发
查看>>
漂亮的蓝色风格网页设计作品欣赏(系列二)
查看>>
Bind和Eval的区别详解
查看>>
血拼2011中国移动开发者大会门票超低价团购!(已结束)
查看>>
Ural_1348. Goat in the Garden 2(计算几何)
查看>>
Mysql学习积累之二[网摘收藏 个人学习参考]
查看>>
[nodejs]Buffer vs String
查看>>
IIS负载均衡-Application Request Route详解第五篇:使用ARR来配置试点项目
查看>>