2

I have a UITableView whose frame is set to the parent view's frame size. The table view appears just fine on an iPhone. However, on an iPad, it has this thick margin on both sides.

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. 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?

Sayak Banerjee
  • 1,954
  • 3
  • 25
  • 58
  • have a look at this question: [iOS 8 UITableView separator inset 0 not working](http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working) – duan Nov 07 '15 at 04:15
  • Check this http://stackoverflow.com/questions/30819689/set-beginning-of-separator-lines-in-uitableview/30819751#30819751 May you get help from this or http://stackoverflow.com/questions/30168168/separator-lines-for-uitableviewcellstylesubtitle-cells-not-taking-the-full-width/30168203#30168203 This – Ashish Kakkad Nov 07 '15 at 04:45
  • Thanks for your replies. I tried all of the solutions (preserveSuperviewMargins, all forms of margins, also added NSLayoutConstraints, but the margins on both sides are still there. – Sayak Banerjee Nov 07 '15 at 05:18

2 Answers2

5

here it is:

tableView.cellLayoutMarginsFollowReadableWidth = false

From Apple Docs:

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. 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

the Reverend
  • 12,305
  • 10
  • 66
  • 121
0

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.

RStack
  • 230
  • 4
  • 16