Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Safe Area layout in iPhone x

I am developing Xamarin forms app and my app seems with safe area set in top. But need to ignore it.

Current scenario:

enter image description here

Excepted scenario:

enter image description here

I have googled regarding this and got below link, tried out as mentioned in below links and nothing worked.

https://forums.xamarin.com/discussion/104945/iphone-x-and-safe-margins-with-xamarin-forms
https://blog.xamarin.com/making-ios-11-even-easier-xamarin-forms/

But didn’t know how to access SetPrefersLargeTitles under Xamarin forms content page in below line mentioned in above link.

On<Xamarin.Forms.PlatformConfiguration.iOS>().SetPrefersLargeTitles(true);

After set safe area as true output come as below, enter image description here

Please help me to resolve this.

Regards, Cheran

like image 225
cheran Avatar asked Mar 15 '18 06:03

cheran


People also ask

What is safe area in iPhone?

Safe areas help you place your views within the visible portion of the overall interface. UIKit-defined view controllers may position special views on top of your content. For example, a navigation controller displays a navigation bar on top of the underlying view controller's content.

What is the height of safe area iOS?

TLDR — Safe area is 44pt from the top and 34pt from the bottom in portrait mode on new iPhone devices, treat them as the edge of the screen in your design.

What is safe layout?

The safe area layout guide is a property of the UIView class and it inherits from the UILayoutGuide class. It was introduced in iOS 11 and tvOS 11. It helps you correctly position views in a layout. The safe area layout guide replaces the top and bottom layout guides of the UIViewController class.

How do I disable safe area layout guide?

You can disable safe area layout guide from storyboard for particular view controller. Select View Controller -> File Inspector (first tab) -> Use safe area layout guides (uncheck the checkbox).


3 Answers

You can do it from XAML like this

xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" 
ios:Page.UseSafeArea="true"
like image 122
Rasmus Christensen Avatar answered Oct 08 '22 23:10

Rasmus Christensen


Please Refer to Making iOS 11 Even Easier with Xamarin.Forms

We use Platform-Specifics to implement it.

Before iOS 11

On<Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true);

iOS 11 or newer

var safeInsets  = On<Xamarin.Forms.PlatformConfiguration.iOS>().SafeAreaInsets();
safeInsets.Left = 24;
this.Padding = safeInsets;
like image 38
ColeX - MSFT Avatar answered Oct 08 '22 21:10

ColeX - MSFT


It's necessary to create or configure LaunchScreend.storyboard.

Use this code, change splash_screen for your image.

like image 42
Dionis Oliveira Avatar answered Oct 08 '22 22:10

Dionis Oliveira