Reputation:
How do I add space above the first tableview section? You can see that the first section: "A", doesn't have the right above it. Here's an image: https://docs.google.com/document/d/1QRuL_aoSQNbg-SLlrcAzcQGT1L7gBCTgg-ji-XTHXjY/edit?usp=sharing Tried changing UITableview content offset in viewDidLoad, but that didn't work. Suggestions?
Upvotes: 3
Views: 2389
Reputation: 2044
As UITableView
is a subclass of UIScrollView
better use contentInset
property of your table view as described in "Creating and Configuring Scroll Views" of Apple developer's library.
Simply put this code in a place where you initialize or configure your table view:
CGFloat topInset = 10; //change this value as needed
tableView.contentInset = UIEdgeInsets(top:topInset, left: 0, bottom: 0, right: 0)
UPDATE for Swift 4
let topInset: CGFloat = 10
myTableView.contentInset.top = topInset
Upvotes: 17