zoukankan      html  css  js  c++  java
  • 改变tableView中的cell选中的颜色和背景颜色 从父视图上删除所有的子视图

    1. 1.系统默认的颜色设置  
    [cpp] view plaincopy
     
    1. //无色  
    2. cell.selectionStyle = UITableViewCellSelectionStyleNone;  
    3.   
    4. //蓝色  
    5. cell.selectionStyle = UITableViewCellSelectionStyleBlue;  
    6.   
    7. //灰色  
    8. cell.selectionStyle = UITableViewCellSelectionStyleGray;  

     

    2.自定义颜色和背景设置

     改变UITableViewCell选中时背景色:

     

    UIColor *color = [[UIColoralloc]initWithRed:0.0green:0.0blue:0.0alpha:1];//通过RGB来定义自己的颜色

    [html] view plaincopy
     
    1. cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:cell.frame] autorelease];  
    2. cell.selectedBackgroundView.backgroundColor = [UIColor xxxxxx];  

     

     

    3自定义UITableViewCell选中时背景

    [html] view plaincopy
     
    1. cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellart.png"]] autorelease];   
    2. 还有字体颜色   
    3. cell.textLabel.highlightedTextColor = [UIColor xxxcolor];  [cell.textLabel setTextColor:color];//设置cell的字体的颜色  

     

    4.设置tableViewCell间的分割线的颜色


    [theTableView setSeparatorColor:[UIColor xxxx ]];


    4.pop返回table时,cell自动取消选中状态

    首先我有一个UITableViewController,其中每个UITableViewCell点击后都会push另一个 ViewController,每次点击Cell的时候,Cell都会被选中,当从push的ViewController返回的时候选中的Cell便会 自动取消选中。后来由于某些原因我把这个UITableViewController改成了UIViewController,之后就产生了一个问题:每 次返回到TableView的时候,之前选中的Cell不能自动取消选中,经过查找得知:

    UITableViewController有一个clearsSelectionOnViewWillAppear的property,

    而当把UITableViewController修改成UIViewController后,这个属性自然就不存在了,因此我们必须手动添加取消选中的功能,方法很简单,在viewWillAppear方法中加入:

    [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];

    6.点击后,过段时间cell自动取消选中

     - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

         …………

        //消除cell选择痕迹

        [self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];

    }

    - (void)deselect

    {

        [self.tableview deselectRowAtIndexPath:[self.tableview indexPathForSelectedRow] animated:YES];

    }

    从父视图上删除所有的子视图:

    [self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

  • 相关阅读:
    加载时间分析与优化
    t
    linux 3389
    切片声明 切片在内存中的组织方式 reslice
    从模版生成 uri Golang 的 html/template 包不太适合于这种情况
    负载均衡实现,一个域名对应多个IP地址
    京东首页 淘宝首页 图片加载 单域名 多域名 图片服务
    Reduce DNS Lookups 减少DNS查找
    Make Fewer HTTP Requests 减少HTTP请求
    What the 80/20 Rule Tells Us about Reducing HTTP Requests
  • 原文地址:https://www.cnblogs.com/lxllanou/p/3734334.html
Copyright © 2011-2022 走看看