Xaml does not recognize the -568h
or @2x
e.t.c for iOS. It chooses the image which matches the exact name without extension. It works in android because all images have the same name and the resolution folders are different.
As a workaround you can set images from the C# code behind by looking at the height/width by Overriding the OnSizeAllocated method.
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
string BackGroundImgName = "myimage";
Device.OnPlatform(iOS: () =>
{
if (width >= 414)
// iPhone 6 Plus
this.BackgroundImage = BackGroundImgName + "[email protected]";
else if (width >= 375)
// iPhone 6
this.BackgroundImage = BackGroundImgName + "[email protected]";
else if (width >= 320 && height >= 500)
// iPhone 5
this.BackgroundImage = BackGroundImgName + "[email protected]";
else if (width >= 320)
// iPhone 4
this.BackgroundImage = BackGroundImgName + "@2x.png";
else
this.BackgroundImage = BackGroundImgName + ".png";
},
Android: () => { this.BackgroundImage = BackGroundImgName + ".png"; }
);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…