0

As shown here we can leave space for the iOS status bar by using SetUseSafeArea.

But is there something similar for a Xamarin.iOS app that is not a Xamarin.Forms app?

ispiro
  • 26,556
  • 38
  • 136
  • 291
  • 1
    UIView's SafeAreaInsets is what you are looking for: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc – SushiHangover Aug 25 '20 at 20:40
  • @SushiHangover Thanks. I'll check it as soon as my app stops crashing on start :( (It didn't use to do that.) – ispiro Aug 25 '20 at 20:53

2 Answers2

1

First, you can refer to safeAreaLayoutGuide from Apple document, then there is another similar discussion about navitve iOS how to achieve that, you also can refer to do the same in Xamarin.iOS.

Here is the Xamarin.iOS sample code for reference:

public override void ViewDidAppear(bool animated)
{
    base.ViewDidAppear(animated);
    
    //suberView is your subview view in ViewController
    View.Add(suberView);
    suberView.TranslatesAutoresizingMaskIntoConstraints = false;

    var safeGuide = View.SafeAreaLayoutGuide;
    suberView.LeadingAnchor.ConstraintEqualTo(safeGuide.LeadingAnchor).Active = true;
    suberView.TrailingAnchor.ConstraintEqualTo(safeGuide.TrailingAnchor).Active = true;
    suberView.TopAnchor.ConstraintEqualTo(safeGuide.TopAnchor).Active = true;
    suberView.BottomAnchor.ConstraintEqualTo(safeGuide.BottomAnchor).Active = true;

    View.LayoutIfNeeded();
}
Junior Jiang
  • 12,430
  • 1
  • 10
  • 30
0

If you are using native, I think the UIView has something very similar. UseSafeArea or something similar. You should be able to search developer.apple.com for UIView and it should provide something for you to enable.

EDIT: Just noticed SushiHangover's comment. Click on the link Sushi provided and it will show you.

Laymans Code
  • 82
  • 1
  • 7