UITableView的一些常用功能实现代码

//1.定义cell

static NSString * ID=@"hero";

    //1.1首先需要进行判断时候需要创建UITableViewCell对象

    UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:ID];//1.2首先需要从缓存池中找到标识符为hero的UITableViewCell对象

    if(cell ==nil)//缓存池中没有才开始创建

    {

        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];

    }

//2.创建UIView

UIView * view=[[UIView alloc]initWithFrame:cell.frame];

    //改变cell颜色交替显示

    if(indexPath.row%2)    {

        view.backgroundColor=[UIColor grayColor];

    }

//3.将该UIView添加到UITableViewCell中进行颜色隔行显示

    cell.backgroundView=view;

 

//4.选中后UITableViewCell颜色改变

UIView * bgView=[[UIView alloc]initWithFrame:cell.frame];

bgView.backgroundColor=[UIColor redColor];    

cell.selectedBackgroundView=bgView;//选中后的颜色设置

 

//5.改变UITableView中的分割线的颜色和样式

//UITableView控件 self.tableView.

self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;//不显示

self.tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;//显示成横线

self.tableView.separatorColor=[UIColor redColor];//线的颜色是红色

 

//右边详细按钮

    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

转载于:https://www.cnblogs.com/Lofterido/p/3978299.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值