21、[ iOS ] UITableViewCell 的分割线向右偏移15  问题解决

iOS7情况下:

  tableView.separatorInset = UIEdgeInsetsZero;

iOS8、9情况下:

首先在viewDidLoad方法中加上如下代码:
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset: UIEdgeInsetsZero];
    }
    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins: UIEdgeInsetsZero];
    }
然后再加上这个方法:
  - (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];
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.尺寸适配1.原因 iOS7中所有导航栏都为半透明,导航栏(height=44)和状态栏(height=20)不...
    LZM轮回阅读 6,143评论 1 4
  • 随着孩子一天天的长大,他们逐渐形成自己的思维和想法,慢慢的家长会对其越来越难管教。很多时候会发现自己叫着孩子...
    Cici626阅读 677评论 0 0
  • 我感恩自己可以如此这般的幸运! 我感恩我的父母,尽他们所能给我最好的生活,教育和爱护! 我感恩我的妈妈,用她能给的...
    Twinkle_L阅读 352评论 1 0