问题描述
我在 iOS 9
上的 UITableView
中的 UITableViewCell
之间的分隔符有问题.他们有显着的左边距.我已经有删除 iOS 8
引入的间距的代码,但它不适用于 iOS 9
.看起来他们添加了其他东西.我想它可能与 layoutMarginsGuide 但我还没弄明白.有没有人遇到过类似的问题并找到了解决方案?
I have a problem with separators between UITableViewCell
s 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 分隔符插入(显着的左边距)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!