简体   繁体   English

UITableView分隔符在iPad的两边都有边距

[英]UITableView separator has margins on both sides in iPad

I have a UITableView whose frame is set to the parent view's frame size. 我有一个UITableView,其框架设置为父视图的框架大小。 The table view appears just fine on an iPhone. 表格视图在iPhone上看起来很好。 However, on an iPad, it has this thick margin on both sides. 但是,在iPad上,其两边都有很大的空白。

If I select the cell, it shows that the table does indeed span the whole width. 如果选择该单元格,则表明表格确实覆盖了整个宽度。 However, the separators seem to be smaller. 但是,分隔符似乎较小。 I have tried setting the layoutMargins to zero, but it has no effect. 我尝试将layoutMargins设置为零,但没有任何效果。 Here is how I add it to my view: 这是将其添加到视图中的方法:

self.optionsView = UITableView()
self.optionsView.delegate = self
self.optionsView.dataSource = self
self.optionsView.hidden = true
self.optionsView.frame.origin = CGPoint(x: view.frame.size.width + 30, y: 0)
self.optionsView.frame.size = view.frame.size
self.optionsView.layer.shadowColor = Palette.shadowColor.CGColor
self.optionsView.layer.shadowRadius = 10.0
self.optionsView.layer.shadowOpacity = 0.3
self.optionsView.clipsToBounds = false

view.addSubview(optionsView)

Any idea what's going wrong here? 知道这里出了什么问题吗?

here it is: 这里是:

tableView.cellLayoutMarginsFollowReadableWidth = false

From Apple Docs: 从Apple Docs:

CellLayoutMarginsFollowReadableWidth : CellLayoutMarginsFollowReadableWidth

A Boolean value that indicates whether the cell margins are derived from the width of the readable content guide. 一个布尔值,指示是否从可读内容指南的宽度中得出单元格边距。

What is the Readable Content Guide: 什么是可读内容指南:

A layout guide representing an area with a readable width within the view. 布局指南,表示视图中具有可读宽度的区域。

Discussion : 讨论内容

This layout guide defines an area that can easily be read without forcing users to move their head to track the lines. 该布局指南定义了一个易于阅读的区域,而无需强迫用户移动其头部来跟踪线条。 The readable content area follows the following rules: 可读内容区域遵循以下规则:

The readable content guide never extends beyond the view's layout margin guide. 可读的内容指南绝不会超出视图的布局边距指南。

The readable content guide is vertically centered inside the layout margin guide. 可读内容指南垂直于布局边距指南的中心。

The readable content guide's width is equal to or less than the readable width defined for the current dynamic text size. 可读内容指南的宽度等于或小于为当前动态文本大小定义的可读宽度。

Use the readable content guide to lay out a single column of text. 使用可读的内容指南来布置单列文本。 If you are laying out multiple columns, you can use the guide's width to determine the optimal width for your columns. 如果要布置多列,则可以使用指南的宽度来确定列的最佳宽度。

Conclusion: 结论:

Apple decided that you would be using by default their dynamic text engine and only 1 column on your table views. Apple决定默认情况下将使用其动态文本引擎,并且表视图上仅使用一列。 If you are not in this scenario, you should probably turn off this property. 如果您不在这种情况下,则可能应该关闭此属性。 If you want to know the value for the readable width you can get it like this: 如果您想知道可读宽度的值,可以这样获得:

tableView.readableContentGuide.layoutFrame.width tableView.readableContentGuide.layoutFrame.width

Keep a break point on this line 在这条线上保持断点

self.optionsView.frame.size = view.frame.size

and check what is the frame size for view .You will be able to understand more after that. 并查看要view的框架尺寸。之后,您将能够了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM