• ios7 ios8 cell中下划线偏移(separator Insets)处理方法


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

    [self.tableView setSeparatorInset:UIEdgeInsetsZero];

    }

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {

    [self.tableView setLayoutMargins:UIEdgeInsetsZero];

    }

    然后在UITableView的代理方法中加入以下代码 - (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];

    }

    }

     以上内容来自:http://www.bugfly.cn/?id=35

    但是以上内容某些情况下还是有问题 可以参考这个以下这个处理:

    在xib中对tableview的separator insets做设置,custom类型left,right都赋值成0,但实际显示的时候会发现左边还是有15px的边距。

    问题解决帖:

    http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working

    文中描述了多种解决方式,我只尝试了一种,已经解决了该问题。

    即对子类化的自定义cell类,覆盖layoutMargins属性的getter方法。

    - (UIEdgeInsets)layoutMargins
    {
    return UIEdgeInsetsZero;
    }

  • 相关阅读:
    UVA 10617 Again Palindrome
    UVA 10154 Weights and Measures
    UVA 10201 Adventures in Moving Part IV
    UVA 10313 Pay the Price
    UVA 10271 Chopsticks
    Restore DB後設置指引 for maximo
    每行SQL語句加go換行
    种服务器角色所拥有的权限
    Framework X support IPV6?
    模擬DeadLock
  • 原文地址:https://www.cnblogs.com/programmer-blog/p/4538364.html
Copyright © 2020-2023  润新知