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

is there a way of setting this in Storyboard?

3254523
  • 3,016
  • 7
  • 29
  • 43

3 Answers3

41

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

Dasoga
  • 5,489
  • 4
  • 33
  • 40
Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127
  • 2
    Good job! But look out the `automaticallyAdjustsScrollViewInsets` property of `UIViewController`. – KudoCC Sep 16 '15 at 07:43
  • 2
    @ZhouHao This question is about `UITableView`. `UILabel` doesn't support content insets natively. See here for solutions: http://stackoverflow.com/questions/19437579/ios-add-left-padding-to-uilabel – Lars Blumberg Nov 02 '16 at 09:54
  • Shock content . – beefon Mar 14 '18 at 09:06
  • 1
    Has anyone any idea why Apple is so fund of removing features from their products? Correct answer btw. – gujci Jan 23 '19 at 15:44
11

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.

KudoCC
  • 6,912
  • 1
  • 24
  • 53
  • @kudosCC - the Content Insets parameters do not appear on Xcode 5 (beta 6)... any chance you know why? – 3254523 Aug 08 '14 at 16:13
  • @christopher.ryan.cruz My Xcode version is 5.1.1, make sure the UITableView is selected. – KudoCC Aug 08 '14 at 21:14
  • ah, i'm on xcode 6 actually - there seems to be a bug that hides the content inset parameters – 3254523 Aug 08 '14 at 21:16
  • @christopher.ryan.cruz Maybe it is a bug or this function is moved to other place. Well, I haven't downloaded Xcode 6 yet. – KudoCC Aug 08 '14 at 21:27
  • This section is missing from XCode 6 – Jonas Alves Oct 03 '14 at 20:58
  • @JonasAlves No, it still in the Size inspector. Updated my answer for Xcode 6. – KudoCC Oct 03 '14 at 22:17
  • 3
    @KudoCC I insist it's not. There is only "indicator insets" there for UITableView. XCode 6.0.1 – Jonas Alves Oct 04 '14 at 03:49
  • 3
    @KudoCC - not sure what's happening but I'll back up what Jonas says - It's not there! Scroll View section has Indicator Insets but NO Content Insets (xcode 6.0.1) See image at http://stackoverflow.com/q/25207927/558575 for corroboration. – amergin Oct 20 '14 at 16:04
  • Any idea why there's no content inserts anymore in XCode 7 (in IB)? How are we supposed to do this now in IB? – User Sep 02 '15 at 23:39
  • @lxx I think we can't do it in IB now. : ( – KudoCC Sep 04 '15 at 02:51
  • 1
    @KudoCC I added an answer that suggests a solution for setting the content insets in the storyboard for Xcode 6+. – Lars Blumberg Sep 16 '15 at 07:36
  • Still not there in Xcode 7. Lars Blumberg's answer remains the only solution within IB. – Jonny Jan 31 '16 at 16:38
1

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)

Sylvain
  • 118
  • 8