iOS 9 UITableView分隔符插入(显着的左边距) [英] iOS 9 UITableView separators insets (significant left margin)

查看:232
本文介绍了iOS 9 UITableView分隔符插入(显着的左边距)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UITableViewCell iOS 9上的 UITableView 之间的分隔符有问题/ code>。它们具有显着的左边距。我已经有了删除由 iOS 8 引入的间距的代码,但它不适用于 iOS 9 。看起来他们添加了别的东西。我想它可能与 layoutMarginsGuide 但我还没想出来。有没有人有类似的问题并找到解决方案?

I have a problem with separators between UITableViewCells in UITableView on iOS 9. They have the significant left margin. I already have code for removing spacing introduced by iOS 8 but it doesn't work with iOS 9. It looks like they added something else. I suppose it might be connected with layoutMarginsGuide but I haven't figured it out yet. Does anyone had a similar problem and found out the solution?

推荐答案

好的,我找到了解决方案。唯一需要的是设置 UITableView 的呈现实例,该标志 cellLayoutMarginsFollowReadableWidth

Okay, I have found out the solution. The only thing required for that is to set on the presenting instance of UITableView that flag cellLayoutMarginsFollowReadableWidth

myTableView.cellLayoutMarginsFollowReadableWidth = NO;

我想在文档中找到一些参考文献,但它看起来还没准备好,仅在差异页面上提及

I wanted to find some reference in the documentation but it looks like it is not ready yet, only mentioned on diff page.

由于该标志是在iOS 9中引入的,为了向后兼容,您应该在尝试设置之前添加一个检查:

As the flag was introduced in iOS 9 for the backward compatibility you should add a check before trying to set it:

if([myTableView respondsToSelector:@selector(setCellLayoutMarginsFollowReadableWidth:)])
{
    myTableView.cellLayoutMarginsFollowReadableWidth = NO;
}

对于 Swift 2.0 您可以使用 #available 来检查iOS版本。

For Swift 2.0 you can use #available to check iOS version.

if #available(iOS 9, *) {
    myTableView.cellLayoutMarginsFollowReadableWidth = false
}

此外,您需要使用 Xcode 7 或更高版本进行编译。

Moreover you need to compile it with Xcode 7 or above.

编辑

请记住,如果您的分隔符在iOS 8中看起来很好,这是唯一需要的修复,否则您需要更改一点。您可以在SO上找到有关如何执行此操作的信息。

Please keep in mind that this is the only required fix if your separators looked "fine" up to iOS 8, otherwise you need to change a bit more. You can find info how to do this already on SO.

这篇关于iOS 9 UITableView分隔符插入(显着的左边距)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆