Xamarin Forms - Status bar overlaps the content in IOS (safeareainsets issue) - xamarin

In Xamarin Forms, I am using
<ContentPage
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
ios:Page.UseSafeArea="true" >
to make the Application UI compatible with iPhone X, but its working only in iOS 11. Anyone have a suggestion on how to make this work on all iOS devices?

The concept of the safe area is exclusive to iPhone X, hence to iOS 11+. Anyway, per default an app uses the whole phones screen (as opposed to Android), hence, if the status bar is shown (you can hide it if you need, but that's another story), your app will overlap it.
Xamarin.Forms NavigationPage will automatically adapt to the available area (others maybe too), but if you are using a bare ContentPage for example, you'll have to take care of by yourself.
To handle things differently on different platforms, there is the OnPlatform tag in XAML (see here). With that you can add a platform-dependent padding to your ContentPage
<ContentPage.Padding>
<OnPlatform x:TypeArguments="Thickness">
<On Platform="iOS" Value="0,20,0,0" />
</OnPlatform>
</ContentPage.Padding>
which will prevent your page overlapping the status bar.

Related

How to change Android ActionBar color in Xamarin App.Shell

I'm developing an app using Xamarin with .netstandard 2.1 and can't find a way to change the action bar of the android app.
The blue bar isn't the color I want, and following all the docs and tutorials over internet, I found even a way to change the status bar (where the clock and battery and notifications are), but can't change this blue to Orange.
Can someone tell me what should I'm doing wrong, please?
Thanks
Set the attached property BackgroundColor="Red" either globally at <Shell> level:
<Shell
...
BackgroundColor="Red">
Or at ContentPage level using:
<ContentPage
...
Shell.BackgroundColor="Red">
note that this will affect navigation bar (the one you described) and also upper tabs (TabBar).
Inside your shell app xaml file, at the top use Shell.BackgroundColor="Red".
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App1.Views"
Title="App1"
x:Class="App1.AppShell"
Shell.BackgroundColor="Red"
>

Controls are disabled in MenuItems used in Shell in Xamarin Forms

The code below when entered in AppShell for Xamarin Forms only works in Android. In iOS the Switch is rendered but can't be toggled (as if it is disabled). Are there any tricks to making this work in iOS as well or is this a bug?
I tried placing the the Switch in a completely different ContentView and loading it in the Shell with local: and also tried including the Switch in the DataTemplate directly. All of them work in Android, just not iOS.
Thanks for your help
<MenuItem>
<Shell.MenuItemTemplate>
<DataTemplate>
<ContentView>
<Switch IsToggled="True" />
</ContentView>
</DataTemplate>
</Shell.MenuItemTemplate>
</MenuItem>

What are the sizes of images to take into account in Xamarin multiplatform

my question is the following, I am doing a project in Xamarin for Android, IOS and UWP.
Currently as we all know, these systems have different types of screens, so when loading a background image into the ContentPage it should be in different measures in the project resources folder.
I have the following:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AppFalcon"
x:Class="AppFalcon.MainPage"
BackgroundImage="Background.jpg">
</ContentPage>
I want to know the size for all projects, because in Android the background image works great, but in IOS the image is only half.
Thank you very much in advance.

Xamarin Forms Bottom Navigation Bar

In my Xamarin forms application I need to add a bottom navigation bar in every pages. Bottom navigation bar should have 7 buttons and tapping on each buttons should navigate to corresponding pages. Is there any way to implement this in Xamarin forms?
Yes I have implemented this using this plugin Bottom Bar Plugin it is a very useful plugin which renders tab bars at the bottom of the screen for android and IOS. Even though all the documentation you will need is available via the link I mention, the stackoverflow bots will swarm me unless I add that you can navigate to the site in question by searching google for
BottomNavigationBarXF
other than cutting and pasting their documentation for the benefit of this site (so that anyone referrring to this answer in the event of a thermo nuclear war, after which stackoverflow is the only surviving site, can still contextualise this answer), I would urge you to consult their documentation which is well put together.
You can use Tab page itself. For iOS, by default tab pages button are at bottom. For Android, there is a way to move the tabs to bottom. You need to update Xamarin or Visual Studio. After updating, add the below page directives to the Tab page Xaml code.
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
For example:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TabbedPageWithNavigationPage;assembly=TabbedPageWithNavigationPage"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.BarItemColor="#a39d9f"
android:TabbedPage.BarSelectedItemColor="#007aff"
android:TabbedPage.IsSwipePagingEnabled="false"
x:Class="TabbedPageWithNavigationPage.MainPage">
<local:TodayPage />
<NavigationPage Title="Schedule" Icon="schedule.png">
<x:Arguments>
<local:SchedulePage />
</x:Arguments>
</NavigationPage>

Can I use standard icons from Windows Phone in a ToolbarItem?

I have a Xamarin Forms page with a toolbar item like this:
<ToolbarItem Name="Cancel">
<ToolbarItem.Icon>
<OnPlatform x:TypeArguments="FileImageSource" WinPhone="button_cancel.png" />
</ToolbarItem.Icon>
</ToolbarItem>
This is using a bitmap for showing a cancel icon in Windows Phone. But in Windows Phone there is already predefined icons like this (in the Segoe UI Symbol font). Can I use them instead of bitmaps?
You can make a custom renderer for a NavigationPage which then replaces normal images sources to the native one while using custom fonts. More here (examples are for Android and iOS but should be easily adopted to Windows too: https://forums.xamarin.com/discussion/17278/custom-font-in-xamarin-forms-font-awesome/p1

Resources