Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Developing same UI for 3.5, 4.0 (updated 4.7 and 5.5) inches screens in Xcode 5.0.1 (updated xcode 6), no landscape, no iPad and no storyboard

  1. I have developed app considering 3.5 inch with .xib files and not storyboard.
  2. I am unable to find any tutorial or guide which will help me in designing app similar for all screens.
  3. I am using Xcode 5.0.1
  4. I am developing only plain app with no auto layout and only for iOS 6 and iOS 7 (IPhone).
  5. Below is the screenshot how it differs on different screens.

    A. IPhone iOS 6 simulator: IPhone iOS 6 simulator

    B. 3.5 Inch (Ios 6 and Ios 7) 3.5 Inch (Ios 6 and Ios 7) C. 4.0 Inch (Ios 6 and Ios 7) 4.0 Inch (Ios 6 and Ios 7)

Update: Please update below answers to also know 4.7 and 5.5 inches screen. enter image description here

like image 723
Yogesh Lolusare Avatar asked Dec 10 '13 08:12

Yogesh Lolusare


3 Answers

If you want check it Programmatically :

FOR Swift

extension UIDevice {

 var iPhoneX: Bool {
    return UIScreen.main.nativeBounds.height == 2436
 }
 var iPhone: Bool {
    return UIDevice.current.userInterfaceIdiom == .phone
 }
 enum ScreenType: String {
    case iPhone4_4S = "iPhone 4 or iPhone 4S"
    case iPhones_5_5s_5c_SE = "iPhone 5, iPhone 5s, iPhone 5c or iPhone SE"
    case iPhones_6_6s_7_8 = "iPhone 6, iPhone 6S, iPhone 7 or iPhone 8"
    case iPhones_6Plus_6sPlus_7Plus_8Plus = "iPhone 6 Plus, iPhone 6S Plus, iPhone 7 Plus or iPhone 8 Plus"
    case iPhoneXR = "iPhone XR"
    case iPhoneX_iPhoneXS = "iPhone X,iPhoneXS"
    case iPhoneXSMax = "iPhoneXS Max"
    case unknown
 }

 var screenType: ScreenType {
    switch UIScreen.main.nativeBounds.height {
    case 960:
        return .iPhone4_4S
    case 1136:
        return .iPhones_5_5s_5c_SE
    case 1334:
        return .iPhones_6_6s_7_8
    case 1792:
        return .iPhoneXR
    case 1920, 2208:
        return .iPhones_6Plus_6sPlus_7Plus_8Plus
    case 2436:
        return .iPhoneX_iPhoneXS
    case 2688:
        return .iPhoneXSMax
    default:
        return .unknown
    }
  }
}

You can check like:

print("screenType:", UIDevice.current.screenType.rawValue)

For checking Retina (3.5/4 inch Screen) or Non-Retina

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    if ([[UIScreen mainScreen] scale] == 2.0) {
       if([UIScreen mainScreen].bounds.size.height == 568){
          // iPhone retina-4 inch
        } else{
         // iPhone retina-3.5 inch
        }
}
else {
    // not retina display
}

Update:

For checking All retina iPhone Programmatically:

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
      if ([[UIScreen mainScreen] scale] == 2.0) {

           if([UIScreen mainScreen].bounds.size.height == 667){
             // iPhone retina-4.7 inch(iPhone 6)
           } 
           else if([UIScreen mainScreen].bounds.size.height == 568){
             // iPhone retina-4 inch(iPhone 5 or 5s)
           } 
           else{
            // iPhone retina-3.5 inch(iPhone 4s)
          }
      }
      else if ([[UIScreen mainScreen] scale] == 3.0)
      {
           //if you want to detect the iPhone 6+ only 
           if([UIScreen mainScreen].bounds.size.height == 736.0){
              //iPhone retina-5.5 inch screen(iPhone 6 plus)
           }
           //iPhone retina-5.5 inch screen(iPhone 6 plus)
      }
 }

Also check this

#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)
#define IS_IPHONE_6_PLUS (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0)

may it will help you .

Happy coding.

like image 128
Dhaval Bhadania Avatar answered Oct 14 '22 00:10

Dhaval Bhadania


Put below lines in prefix.pch

#define IS_DEVICE_RUNNING_IOS_7_AND_ABOVE() ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
#define iPhoneVersion ([[UIScreen mainScreen] bounds].size.height == 568 ? 5 : ([[UIScreen mainScreen] bounds].size.height == 480 ? 4 : ([[UIScreen mainScreen] bounds].size.height == 667 ? 6 : ([[UIScreen mainScreen] bounds].size.height == 736 ? 61 : 999))))

Now in programming you can say...

if (IS_DEVICE_RUNNING_IOS_7_AND_ABOVE()) {
    NSLog("This is iOS 7");
} else {
    NSLog("This is iOS 6 or below");
}


if (iPhoneVersion==4) {
    NSLog("This is 3.5 inch iPhone - iPhone 4s or below");
} else if (iPhoneVersion==5) {
    NSLog("This is 4 inch iPhone - iPhone 5 family");
} else if (iPhoneVersion==6) {
    NSLog("This is 4.7 inch iPhone - iPhone 6");
} else if (iPhoneVersion==61) {
    NSLog("This is 5.5 inch iPhone - iPhone 6 Plus.. The BIGGER");
} else {
    NSLog("This is iPad");
}
like image 7
Fahim Parkar Avatar answered Oct 13 '22 22:10

Fahim Parkar


You can use auto layout or code. In code you can use layoutSubviews method. Just check view height to discover is it a iPhone 3.5 or 4 inch and do your set up:

-(void)layoutSubviews
{
    if (self.view.bounds.size.height == 568)
    {
        [self.textField setFrame:CGRectMake(0, 0, 100, 30)];
        //... other setting for iPhone 4inch
    }
    else
    {
        [self.textField setFrame:CGRectMake(0, 0, 100, 30)];
        //... other setting for iPhone 3.5 inch
    }
}
like image 2
Greg Avatar answered Oct 13 '22 22:10

Greg