美文网首页iOS开发札记
ios7 分割线短 15 像素(废弃) ios8方法

ios7 分割线短 15 像素(废弃) ios8方法

作者: 代码干货 | 来源:发表于2015-08-27 19:42 被阅读129次

在ios7中,UITableViewCell左侧会有默认15像素的空白。这时候,设置setSeparatorInset:UIEdgeInsetsZero 能将空白去掉。
但是在ios8中,设置setSeparatorInset:UIEdgeInsetsZero 已经不起作用了。下面是解决办法
首先在viewDidLoad方法加入以下代码:
<pre>
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
</pre>
然后在UITableView的代理方法中加入以下代码
<pre>

  • (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
    [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
    [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    }
    </pre>

相关文章

网友评论

    本文标题:ios7 分割线短 15 像素(废弃) ios8方法

    本文链接:https://www.haomeiwen.com/subject/dzvhcttx.html