Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't use SafeArea inset on iPhone X for first UITableViewCell

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:

enter image description here

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:

enter image description here

Is there any way to do what I am wanting just for the first cell?

like image 985
Nic Hubbard Avatar asked Jan 04 '18 18:01

Nic Hubbard


People also ask

What is safe inset iOS?

(In tvOS, the safe area reflects the area not covered by the screen's bezel.) You obtain the safe area for a view by applying the insets in this property to the view's bounds rectangle. If the view is not currently installed in a view hierarchy, or is not yet visible onscreen, the edge insets in this property are 0 .

How many pixels is safe area?

On landscape images, the default safe area is approximately 1750 x 1035 pixels, and on portrait images the default safe area is approximately 874 x 1340 pixels.


2 Answers

I found that I needed to uncheck the Content View Insets To Safe Area checkbox that is on the UITableView.

enter image description here

Doing this fixed the issue!

like image 135
Nic Hubbard Avatar answered Oct 05 '22 08:10

Nic Hubbard


Marking the "Content insets" under Size Inspector to "Never" worked for me. enter image description here

like image 22
Van Avatar answered Oct 05 '22 09:10

Van