Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 765
bluefloyd8 Avatar asked Feb 26 '10 05:02

bluefloyd8


2 Answers

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)
like image 192
jigzat Avatar answered Oct 18 '22 21:10

jigzat


Swift 5.1

add the following in viewDidLoad

tableView.contentInset.top = 100

Really that's all there is to it.

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.contentInset.top = 100
}
like image 15
Rom4in Avatar answered Oct 18 '22 23:10

Rom4in