zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    KVC(key value coding)/ KVO(key value observing)
    手势识别
    导航控制器掌握内容:
    火车入轨_算法
    卡片游戏_算法
    Python合集之Python循环语句(一)
    Python合集之Python选择语句(四)
    Python合集之Python选择语句(三)
    Python合集之Python选择语句(二)
    Python合集之Python选择语句(一)
  • 原文地址:https://www.cnblogs.com/programmer-blog/p/4538364.html
Copyright © 2011-2022 走看看