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;
    }

  • 相关阅读:
    javascript数据类型判断
    Week04面向对象设计与继承
    201621044079《Java程序设计》第1周学习总结
    201621044079 week05继承、多态、抽象类与接口
    201621044079《Java程序设计》第二周学习总结
    Week03面向对象入门
    201621044079WEEK06接口、内部类
    202020211 20209320 《Linux内核原理与分析》第一周作业
    第二天:PowerShell别名
    第一天:powershell外部命令
  • 原文地址:https://www.cnblogs.com/programmer-blog/p/4538364.html
Copyright © 2011-2022 走看看