Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something similar to Android's dimens.xml in iOS?

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.

like image 383
Drake Avatar asked Oct 25 '25 14:10

Drake


1 Answers

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.

Create a static Class named 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;
        }
    }      
}

Usage:

View.Height = Dimens.Height;

Here is the plugin which can check your device type.

like image 157
ColeX - MSFT Avatar answered Oct 27 '25 04:10

ColeX - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!