iOS 8下设置cell的分割线缩进separatorInset

http://www.jianshu.com/p/afa312d046e3

iOS 8下设置cell的分割线缩进separatorInset

iOS 7下

想要设置cell的分割线缩进为0,在iOS7中只用简单的设置cell的separatorInset = UIEdgeInsetZero;

iOS 8下

在iOS8下,上面的方法就不行啦,经过查阅资料, 终于在stackoverflow上查到了详细的说明,源地址戳这里stackoverflow;

This property isn't available on iOS 7.0 so you need to make sure you check before assigning it!
Additionally, Apple has added a property to your cell that will prevent it from inheriting your Table View's margin settings. When this property is set, your cells are allowed to configure their own margins independently of the table view. Think of it as an override.
This property is called preservesSuperviewLayoutMargins, and setting it toNO will allow the cell's layoutMargin setting to override whatever layoutMargin is set on your TableView. It both saves time (you don't have to modify the Table View's settings), and is more concise. Please refer to Mike Abdullah's answer for a detailed explanation.

什么意思呢,就让我这个英语四级的战五渣来试着翻译一下吧.

iOS8中,新加入了一个属性:preservesSuperviewLayoutMargins,呐,这个属性的加入,可以避免你的cell的外边继承自你的tableView,当你设置这个属性的时候,你可以自由的设置你的cell的外边距,而不必担心tableView和cell两者的相互影响.(翻译的好渣,你们自己去看英文吧...)

具体怎么代码实现呢

//Setup your cell margins:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
     // Remove seperator inset
     if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
         [cell setSeparatorInset:UIEdgeInsetsZero];
     }
     // Prevent the cell from inheriting the Table View's margin settings
     if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
         [cell setPreservesSuperviewLayoutMargins:NO]; 
      }
     // Explictly set your cell's layout margins 
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
         [cell setLayoutMargins:UIEdgeInsetsZero]; 
    }
}

OVER.


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值