【问题标题】:UITableViewCell separator insets don't work when table.width is much greater than view.width当 table.width 远大于 view.width 时,UITableViewCell 分隔符插入不起作用
【发布时间】:2017-08-04 15:32:53
【问题描述】:

在 iOS 10 上,当 table.width 远大于 view.width 时,UITableViewCell 分隔插入不起作用,我没有在 iOS 版本低于 iOS 10 的设备上尝试过。

code is here on gist

【问题讨论】:

  • 分隔线如果是满的,当tableview.width=600时,但是如果宽度大于700,则分隔线显示左右两边的插入。我在 iPhone5S 上试过

标签: ios objective-c uitableview separator insets


【解决方案1】:

有两种方法可以解决这个问题。

第一个您可以在单元格内容视图中添加分隔线视图。

 UIView* line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableview.frame.size.width, 3)];      
 line.backgroundColor = [UIColor whiteColor];

[cell.contentView addSubview:line];

第二个是苹果提供的一个,也很简单,只需在你声明你的 tableview 的地方添加这行代码

yourTableView.cellLayoutMarginsFollowReadableWidth = NO;

【讨论】:

    【解决方案2】:
    _tableView.cellLayoutMarginsFollowReadableWidth = NO;
    

    它在上面工作。

    参考

    iOS 9 UITableView separators insets (significant left margin)

    Xcode 7 iOS 9 UITableViewCell Separator Inset issue

    【讨论】:

      【解决方案3】:

      您可以使用以下代码在 UITableView 中添加分隔符

       UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 3)];/// change size as you need.       
       separatorLineView.backgroundColor = [UIColor whiteColor];// you can also put image here
       [cell.contentView addSubview:separatorLineView];
      

      并删除UITableView 的默认分隔符。希望对您有所帮助。

      【讨论】:

      • 是的,谢谢。我知道自定义分隔线效果很好。但我想知道为什么系统分隔线有插图。
      猜你喜欢
      • 2023-04-09
      • 2018-02-12
      • 1970-01-01
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      • 2015-10-10
      相关资源
      最近更新 更多