UITableView相关

//以前在使用UITableView的时候, 总是在cell上自己加Label, 遇到cell的accessoryType不同的时候, 需要自己调整Label的大小和位置. 后来发现 UITableViewCell中有textLabel和detailTextLabel可以使用, 系统配置好了大小位置, 可以根据cell的不同Style和大小自动调整.

//textLabel就是放置在cell左边的Label, detailTextLabel就是放置在cell右边的Label, 使用的时候需要把cell的Style设为UITableViewCellStyleValue1.

//代码如下:


UITableViewCell *cell =[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1reuseIdentifier:@"cell"]autorelease];

[cell.textLabelsetText:@"选项"];

[cell.detailTextLabelsetTextColor:[UIColorcolorWithWhite:0.52alpha:1.0]];

[cell.detailTextLabelsetText:@"详细内容"];

cell.accessoryType =UITableViewCellAccessoryNone;//cell没有任何的样式

cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像素;

cell.accessoryType =UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button;

cell.accessoryType =UITableViewCellAccessoryCheckmark;//cell右边的形状是对号;

//改变UITableViewCell选中时背景色

cell.selectedBackgroundView = [[[UIViewalloc]initWithFrame:cell.frame]autorelease];

cell.selectedBackgroundView.backgroundColor =[UIColorredColor];

//这样写在IOS7.0以后 TableViewCell的分割线就不会往右挫15个像素点了

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];

[tableViewsetSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值