zoukankan      html  css  js  c++  java
  • 自定义UITableViewCell的背景颜色

    自定义UITableViewCell的背景颜色,实际上是对cell的contentView的背景颜色进行设置,所以可以有以下方法:

    方法一:
    cell.contentView.backgroundColor = [UIColor redColor];
    方法二:
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
    bgview.opaque = YES;
    bgview.backgroundColor = [UIColor orangeColor];
    [cell setBackgroundView:bgview];

    以上是自定义cell. contentView的背景颜色或view的方法实现cell的自定义背景色,下面有UITableView的UITableViewDelegate方法,也可以实现此效果。代码如下:

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

    {

        if (indexPath.row%2==0) {

            cell.backgroundColor = [UIColorwhiteColor];

        }else {

            cell.backgroundColor = [UIColorlightGrayColor];

        }

    }

  • 相关阅读:
    [HAOI2015]T2
    bzoj1036:[ZJOI2008]树的统计Count
    苹果树
    poj1151 Atlantis
    1593: [Usaco2008 Feb]Hotel 旅馆
    [JSOI2008]最大数maxnumber
    【HNOI2014】米特运输
    【HNOI2013】数列
    Luogu5221 Product
    【CQOI2014】数三角形
  • 原文地址:https://www.cnblogs.com/daguo/p/3118442.html
Copyright © 2011-2022 走看看