I am trying to create my iOS
application completely programmatic without using storyboard
. Now I am struggling for different device orientation Identification
. I did separate UI sizes by using device height but I need to create for landscape
orientation different sizes, For me by using below code I cant handle device orientation.
My Code Below :
// Device difrrentiate
if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) && ((UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)))) {
// The device is an iPhone or iPod touch.
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height == 480) {
// Here I can declare the UI sizes for iPhone 3G & 3GS & 4 & 4S
}
if (result.height == 568) {
// Here I can declare the UI sizes for iPhone 5, 5C & 5S
}
if (result.height == 667) {
// Here I can declare the UI sizes for iPhone 6
}
if (result.height == 736) {
// Here I can declare the UI sizes for iPhone 6 Plus
}
}
} else if ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) && ((UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)))) {
// The device is an iPad and iPad mini running iOS 3.2 or later.
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height == 1024) {
// Here I can declare the UI sizes for iPad, iPad 2, iPad Mini
}
if (result.height == 2048) {
// Here I can declare the UI sizes for iPad Air, iPad Mini Retina
}
}
}