UITableViewCell的4种系统样式详细介绍,以及accessoryView accessoryType selectionStyle

swift版   https://blog.csdn.net/sun6223508/article/details/94392397

 

首先我们看官方文档介绍 

    Default,// Simple cell with text label and optional image view 
(behavior of UITableViewCell in iPhoneOS 2.x)
    Value1,	// Left aligned label on left and right aligned label on
 right with blue text (Used in Settings)
    Value2,	// Right aligned label on left with blue text and left 
aligned label on right (Used in Phone/Contacts)
    Subtitle,// Left aligned label on top and left aligned label on 
bottom with gray text (Used in iPod).

第一种value1模式:主标题在最左边,副标题在最右边。主标题和副标题都是居中对齐。并且可以添加一个图片在最左边,底部像素为1的横线到图片的最右边,它不敢越过图片区域,因为那一块是图片的区域,不允许任何控件踏入。主要用于各个APP设置

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
cell.textLabel.text = @"1";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"]; 
cell.detailTextLabel.text = [dateFormatter stringFromDate:[[Date alloc]init];

第二种value2模式:主标题和副标题在0.618的位置,统称黄金分割,黄金分割是一种数学上的比例关系。黄金分割具有严格的比例性、艺术性、和谐性,蕴藏着丰富的美学价值。主要用于像手机通讯录这样的界面

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"cell"];
cell.textLabel.text = @"1";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"]; 
cell.detailTextLabel.text = [dateFormatter stringFromDate:[[Date alloc]init];

第三种subtitle模式:主标题和副标题左边对齐,主标题在上 副标题在下。并且可以添加一个图片,下面的横线是不到图片区域的。微信的聊天列表就是这样的UI,左边放一个头像,主标题放昵称,副标题放最后一句文字。

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
cell.textLabel.text = @"1";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"]; 
cell.detailTextLabel.text = [dateFormatter stringFromDate:[[Date alloc]init];

 

第四种 default模式:这种模式只有一个主标题在最左边居中。

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.textLabel.text = @"1";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"]; 
cell.detailTextLabel.text = [dateFormatter stringFromDate:[[Date alloc]init];

tip: UITableViewCell里面还有很多属性   比如cell.accessoryView = [[UISwitch alloc]init]效果如图。如果你想做好几个控件放accessoryView,那就用UIView包着cell.accessoryView =UIView


cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式
 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像素;
 
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button;
 
cell.accessoryType = UITableViewCellAccessoryCheckmark;//cell右边的形状是对号;

cell.selectionStyle = UITableViewCellSelectionStyleNone;//无色
cell.selectionStyle = UITableViewCellSelectionStyleBlue;//蓝色
cell.selectionStyle = UITableViewCellSelectionStyleGray;//灰色

 

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值