user3600801
user3600801

Reputation:

Making an ui to be adaptable in various iOS devices

How to make my ui to be adaptable in all iOS devices.While researching , I saw few code where they've defined the sizes of various devices and designed the ui based on the size values. A sample code of how it is defines is as follows,

#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)

Its tedious, if I have to detect size each time. In case of android, there exists fragments to make ui work with various screen size. Is there any alternative for fragments in iOS and How to make my ui to be adaptable in various devices?

Upvotes: 1

Views: 78

Answers (1)

Hardik Vyas
Hardik Vyas

Reputation: 2253

Hello I have one solution for you what i am using in my project.

I am using one simple mathematical equation to do this.

CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width*100/320, [UIScreen mainScreen].bounds.size.height*100/568);

Here i have one view and according to 5s i want it's size with (100x100) so i give that condition that will take size according to screen size increase or decrease.

In 5s it will take 100x100

In 6 it will take (375*100/320) Width and (667*100/568) Height

May be this will help you.

Upvotes: 1

Related Questions