Search code examples
iosuitableviewcocoa-touchuikitcontentoffset

UITableView + Add content offset at top


I need to add some blank space to the top of my UITableView that does not affect the size of the content area. Shifting the content down or adding a blank cell is NOT what I want to do. Instead I just want an offset.

How?


Solution

  • I'm not sure if I'm following you but I think I'm having the same predicament. In my case I must give some space to the ADBannerView at the top of the screen so what I did was in the viewDidLoad method I added:

    [self.tableView setContentInset:UIEdgeInsetsMake(50,0,0,0)];
    

    the values it takes are UIEdgeInsetsMake(top,left,bottom,right).

    Alternatively the same with Swift:

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

    Swift 4.2:

    self.tableView.contentInset = UIEdgeInsets(top: 50, left: 0, bottom: 0, right: 0)