c# - How in Xamarin Forms project use different sizes of BackgroundImage property for Page? -
i've added types of image in resources
- 320 x 480 login-background.png - 640 x 960 login-background@2x.png - 640 x 1136 login-background-568h@2x.png - 750 x 1334 login-background-667h@2x.png
then i've filled backgroundimage property in xaml "image/login-background"
but still not work. both device andthe simulator render 320 x 480.
xaml not recognize -568h
or @2x
e.t.c ios. chooses image matches exact name without extension. works in android because images have same name , resolution folders different.
as workaround can set images c# code behind looking @ height/width overriding 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 + "-736h@3x.png"; else if (width >= 375) // iphone 6 this.backgroundimage = backgroundimgname + "-667h@2x.png"; else if (width >= 320 && height >= 500) // iphone 5 this.backgroundimage = backgroundimgname + "-568h@2x.png"; else if (width >= 320) // iphone 4 this.backgroundimage = backgroundimgname + "@2x.png"; else this.backgroundimage = backgroundimgname + ".png"; }, android: () => { this.backgroundimage = backgroundimgname + ".png"; } ); }
Comments
Post a Comment