Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set a UITableView's contentInset through Storyboard?

self.tableView.contentInset = UIEdgeInsetsMake(232, 0, 232, 0)

is there a way of setting this in Storyboard?

like image 949
3254523 Avatar asked Aug 08 '14 02:08

3254523


3 Answers

The content inset option seems to be gone from the attribute inspector since Xcode 6. But if you don't want to define contentInset in code as it is user interface related, there's still an option left:

Select your UITableView and open the Identity Inspector (Alt+Cmd+3) and click the plus button to add an user defined runtime attribute. Select Rect as its type and contentInset as its key path.

See example here that changes the top inset. 50 appears to be stored as the x value but strangely it changes the top inset.

Reference: {{top, left}, {bottom, right}}

Setting content inset as user defined attributed

like image 167
Lars Blumberg Avatar answered Oct 15 '22 22:10

Lars Blumberg


Yes, UITableView is subclass of UIScrollView, its contentInset property is the property of UIScrollView, so find it in the part of UIScrollView.

enter image description here

For Xcode 6 updated:

enter image description here

I think the reason that I can set contentInset in Xcode 6 is because the project is created before Xcode 6. So if a project is created in Xcode 6 and above, you can't set contentInset. I think that is because in iOS 7 UIViewController will adjust this property accordingly. Look at automaticallyAdjustsScrollViewInsets of UIViewController.

like image 33
KudoCC Avatar answered Oct 16 '22 00:10

KudoCC


In the XIB, the UIScrollView's contentInset keypath, the values are organized in the same order as the UIEdgeInsets constructor:

{{top, left}, {bottom, right}}

UIEdgeInsets(top: 100, left: 0, bottom: 100, right: 0)

like image 1
Sylvain Avatar answered Oct 15 '22 22:10

Sylvain