zoukankan      html  css  js  c++  java
  • UITableViewCell隔行换颜色

    1:在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

      代理方法里面设置颜色转换逻辑;

    2:在-(void)viewDidAppear:(BOOL)animated 

      重新加载 tableview reloadData;

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    
        static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
         
        }
        
       cell.textLable.text = @"hello";
        //Cell隔行换颜色;必须写上 else的颜色可能;
        if (indexPath.row %2 ==0) {
            cell.textLabel.backgroundColor = [UIColor grayColor];
            
        }else{
            cell.textLabel.backgroundColor = [UIColor yellowColor];
    
        }
    
        return cell;
    }
    
    //cell隔行换颜色,需在这里reloadData 一下;
    -(void)viewDidAppear:(BOOL)animated
    {
        [self.tableView reloadData];
    }
    View Code
  • 相关阅读:
    echarts各个配置项详细说明总结
    享元模式
    观察者模式
    策略模式
    桥接模式
    适配器模式
    建造者模式
    原型模式
    单例模式
    Java8新特性——集合底层源码实现的改变
  • 原文地址:https://www.cnblogs.com/cocoajin/p/3089308.html
Copyright © 2011-2022 走看看