I recently found out that I should be placing all my sizing/dimensions in dimens.xml for Android applications that I want to support multiple screen resolutions.
Is there something similar that I should do in iOS to support multiple screen resolutions? I code all my views in the back end (no storyboards) and when I want to position a view (padding, margins, etc.) I simply add hard-coded numbers to the X and Y properties of the view's frame. Same thing for Width, Height, Font size, etc. I imagine my iOS apps that I coded like this will look awkward on different screen resolutions like this?
By the way, I'm using Xamarin (Xamarin.Android and Xamarin.iOS). But I would understand answers using native code.
There is nothing like dimens in iOS.
I believe proper constraints with AutoLayout can work well on padding,margins,Width,Height,etc.
However, if you still want to find a way to achieve it , here is a temporary workaround.
Dimens.public static class Dimens
{
public static int Height
{
get {
string device = DeviceHardware.Model;
if (device.Contains("iPhone4"))
{
return 10;
}
else if (device.Contains("iPhone5"))
{
return 15;
}
else if (device.Equals("iPhone 6") || device.Equals("iPhone 6S"))
{
return 20;
}
else if (device.Equals("iPhone 6 Plus") || device.Equals("iPhone 6S Plus"))
{
return 25;
}
//other device
return 0;
}
}
}
View.Height = Dimens.Height;
Here is the plugin which can check your device type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With