dev-resources.site
for different kinds of informations.
iOS Tips Xamarin Forms - Get Safe Area Height
Published at
9/13/2023
Categories
xamarin
ios
dotnetmaui
mobile
Author
iainrough
Author
9 person written this
iainrough
open
I needed to get the Safe Area height so I could manipulate a screenshot taken on a device. Stack Overflow to the rescue once again.
Yes the project I'm working on has not started the migration to Maui.
Xamarin Forms
Setup the interface.
IGetSafeArea
public interface IGetSafeArea
{
double GetSafeAreaTop();
double GetSafeAreaBottom();
}
Xamarin.iOS
Implement the interface and register it.
GetSafeArea.cs
public class GetSafeArea : IGetSafeArea
{
public double GetSafeAreaBottom()
{
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow();
var bottomPadding = window.SafeAreaInsets.Bottom;
return bottomPadding;
}
return 0;
}
public double GetSafeAreaTop()
{
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
UIWindow window = UIApplication.SharedApplication.Delegate.GetWindow();
var topPadding = window.SafeAreaInsets.Top;
return topPadding;
}
return 0;
}
}
AppDelegate.cs
public partial class AppDelegate : FormsApplicationDelegate
{
...
DependencyService.Register<GetSafeArea>();
...
}
Using It
if (Device.RuntimePlatform == Device.iOS)
{
var safeAreaTop = DependencyService.Get<IGetSafeArea>().GetSafeAreaTop();
}
References
xamarin Article's
30 articles in total
Linux vs macOS vs Microsoft Windows: Which is Best for Software Development?
read article
𝗚𝗲𝘁 𝗗𝗲𝘃𝗘𝘅𝗽𝗿𝗲𝘀𝘀 .𝗡𝗘𝗧 𝗠𝗔𝗨𝗜 𝗖𝗼𝗻𝘁𝗿𝗼𝗹𝘀 𝗳𝗼𝗿 𝗙𝗿𝗲𝗲 𝗕𝗲𝗳𝗼𝗿𝗲 𝗗𝗲𝗰𝗲𝗺𝗯𝗲𝗿 𝟯𝟭, 𝟮𝟬𝟮𝟰!
read article
15 Best Chrome Extensions for Developers: Boost Your Productivity and Workflow
read article
Top 10 iOS Automation Testing Tools for 2025 (with Key Features)
read article
Modern Startup & Login Screens for .NET MAUI + MVVM
read article
UI components for MAUI apps
read article
How to check the MySQL version on Windows, so easy that even a five-year-old can learn it
read article
Building Multi-Page Applications with Xamarin Forms - Tips and Tricks
read article
Mobile Development
read article
.NET MAUI BorderLessEntry for all platforms
read article
Understanding Cross-Platform Development with Xamarin
read article
Navigating Cross-Platform Development: A Comparative Analysis of React Native, Xamarin, Flutter, and Electron
read article
Xamarin vs. React Native: Which Cross-Platform App Development Framework to Choose
read article
Is Xamarin Dead?
read article
Crafting Native Mobile Apps Across Platforms with .NET: Unleashing the Power of Xamarin
read article
iOS Tips Xamarin Forms - Get Safe Area Height
currently reading
Exploring the Most Popular Cross Platform App Development Frameworks
read article
iOS Tips - This app cannot be installed because its integrity could not be verified
read article
Sneak Peek at 2023 Volume 3: Xamarin
read article
My journey in mobile development - From C# to Swift
read article
بهترین آموزش .NET MAUI فارسی
read article
Xamarin/C# app
read article
Flutter Vs Xamarin- Which Is The Best Cross-Platform Development Framework?
read article
Welcome to the New Era of App Development: Introducing Avalonia v11
read article
🔒 Introducing Serial Log and Metro Log: Simplifying Your Logging Experience In .NET MAUI! 📝🚇
read article
How to Build Mobile Check Capture App with Xamarin.Forms and Dynamsoft Document SDK
read article
Sneak Peek at 2023 Volume 2: Xamarin
read article
Incredible App Themes for Xamarin.Forms
read article
Learn how to Integrate Push Notifications in .NET MAUI
read article
App link c# Xamarin
read article
Featured ones: