Reputation: 42165
I have a UITableView
and the first row is used as a sort of header cell with a full bleed background image and other elements. For this cell I do NOT want to use the SafeArea
and I want the UIView
to expand all the way to the edge of the screen. Currently I get this:
I have tried to set this manually for the cell:
if (@available(iOS 11.0, *)) {
headerCell.insetsLayoutMarginsFromSafeArea = NO;
headerCell.layoutMargins = UIEdgeInsetsMake(10, 0, 10, 0);
UIEdgeInsets i = headerCell.layoutMargins;
NSLog(@"Left: %f", i.left);
}
Sadly this doesn't work.
Here is a mockup of what it should look like, with the first cell contents NOT being affected by the safe area:
Is there any way to do what I am wanting just for the first cell?
Upvotes: 9
Views: 8698
Reputation: 187
Just go to the tableview Size inspector and look for the Content Insets by default it will be set to Automatic change that to Never as shown like in the image below
Upvotes: 4
Reputation: 1956
In code, it could be accomplished by
tableView.insetsContentViewsToSafeArea = false
Upvotes: 5
Reputation: 1325
Marking the "Content insets" under Size Inspector to "Never" worked for me.
Upvotes: 11
Reputation: 42165
I found that I needed to uncheck the Content View Insets To Safe Area
checkbox that is on the UITableView.
Doing this fixed the issue!
Upvotes: 14