zoukankan      html  css  js  c++  java
  • UITableView点击背景

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

    - (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];
        }
    }
  • 相关阅读:
    Moodle的安装和登陆(使用Https)
    Moodle 3.4中添加小组、大组、群
    【转】moodle中年级、班级、小组研讨
    函数式接口
    java实现数据库连接池
    转载---jboss简单使用
    转载---数据库优化方案
    转载---虚拟机类加载机制
    java中的hashcode
    父子类静态代码块,非静态代码块,有参,无参构造方法等的执行顺序问题
  • 原文地址:https://www.cnblogs.com/hxwj/p/4731959.html
Copyright © 2011-2022 走看看