'Why does a Xamarin.Forms border draw on top of its contents in iOS, but below its contents in Android

Summary

If the contents of a Frame spill over the edge and if the frame has a border, the frame's border draw on top of the contents on iOS, but below the contents on Android. Is it possible to make the iOS border draw below the contents?

Details

I suspect this may be a bug in Xamarin.Forms, or maybe even the expected behavior on iOS, but nonetheless it is causing problems in my application visuals so I'd like to fix it if possible.

The following code reproduces the problem:

var frameInstance = new Frame();
var grid = new Grid();

AbsoluteLayout.SetLayoutBounds(frameInstance, new Rectangle(58f, 103f, 222f, 304f));
AbsoluteLayout.SetLayoutFlags(frameInstance, AbsoluteLayoutFlags.None);
frameInstance.WidthRequest = 222f;
frameInstance.HeightRequest = 304f;
frameInstance.IsClippedToBounds = false;

frameInstance.HasShadow = false;
frameInstance.CornerRadius = 10;
frameInstance.BorderColor = Color.Gray;



absoluteLayout.Children.Add(frameInstance);

grid.HeightRequest = 42f;
grid.Margin = new Thickness(-32, -32, 0, 0);
grid.HorizontalOptions = LayoutOptions.Fill;
grid.VerticalOptions = LayoutOptions.Start;
grid.BackgroundColor = Color.Red;
frameInstance.Content = grid;

Notice that the frame is hosted in an AbsoluteLayout, but this is not necessary, it can be hosted in any top-level layout object in the page. The important thing is that the frame is offset from the top-left of the page so the contents of the frame can spill over and be seen clearly.

When running On iOS, the code above produces the following image:

enter image description here

If the code is run on Android, it produces the following image:

enter image description here

Is it possible to somehow suppress the rendering of the iOS frame on top of the contents, perhaps through a renderer?

The reason I need to solve this is because my app's login page has an icon which sits halfway over a frame, as shown in the following image (on iOS):

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source