1

Forgive me if this is a really stupid question I am just a beginner at all of this stuff. I want to make a separate interface for the iPhone 6 and 6 Plus but I don't know how the best way to be going about this is. This is a very simple app just to get myself more familiar with the language, etc. I was wondering if there is an easy way to tell if a user is using a 6 or 6 plus to make a separate interface for them. Thanks :)

  • 5
    Use one storyboard for all iPhones. Make proper use of auto layout and constraints to get things in the right place and size. – rmaddy Sep 26 '14 at 22:12
  • This post may also help you: http://stackoverflow.com/questions/25756087/detecting-iphone-6-6-screen-sizes-in-point-values – Anil Sep 26 '14 at 22:16

5 Answers5

2

Use single storyboard. Learn autolayout from raywanderlich, it think its a very good resource.

Also,now take advantage of the size classes introduced for ios 8 in xcode 6. This is called adaptive layout.

So instead of making the above four views for 3.5, 4, 4.7, 5.5 inch devices separately, and then worry about combining their respective landscape modes as well, just go for the 4 combination of size classes using auto layout (if possible, highly recommended) and relax for any other device size that may come into future.

Shrikant Ballal
  • 7,067
  • 7
  • 41
  • 61
Abhishek Arora
  • 395
  • 2
  • 12
0

To detect iPhone Version Please use below code.

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([UIScreen mainScreen].bounds.size.height == 736.0){
              //iPhone retina-5.5 inch screen(iPhone 6 plus)
           }
      }
 }

Reference from Here

Community
  • 1
  • 1
Pradhyuman Chavda
  • 3,814
  • 4
  • 16
  • 24
0

write this code in .pch file

#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)

and wwhenever you need in any controller you simply check the condition.

Daxesh Nagar
  • 1,405
  • 14
  • 22
0

Below are methods that do what you asked. One major thing to look out for is in iOS7 and below, when you check [[UIScreen mainScreen] bounds] for the screen bounds, it always lists the width and height as the same no matter what orientation the phone is in. So if it's an iPhone5 in landscape mode, it will still list the width as 320 and height as 568. In iOS8, this changed, now if that same iPhone5 is in landscape, it will list the width as 568 and the height as 320. Below are methods which account for this:

+ (BOOL) deviceHasFourInchScreen
{
    return [DeviceType deviceHasScreenWithIdiom:UIUserInterfaceIdiomPhone scale:2.0 height:568.0];
}

+ (BOOL) deviceHasFourPointSevenInchScreen
{
    return [DeviceType deviceHasScreenWithIdiom:UIUserInterfaceIdiomPhone scale:2.0 height:667.0];
}

+ (BOOL) deviceHasFivePointFiveInchScreen
{
    return [DeviceType deviceHasScreenWithIdiom:UIUserInterfaceIdiomPhone scale:3.0 height:736.0];
}

+ (BOOL) deviceHasScreenWithIdiom:(UIUserInterfaceIdiom)userInterfaceIdiom scale:(CGFloat)scale height:(CGFloat)height
{
    CGRect mainScreenBounds = [[UIScreen mainScreen] bounds];
    CGFloat mainScreenHeight;

    if ([OperatingSystemVersion operatingSystemVersionLessThan:@"8.0"])
    {
        mainScreenHeight = mainScreenBounds.size.height;
    }
    else
    {
        mainScreenHeight = (UIDeviceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) ? mainScreenBounds.size.width : mainScreenBounds.size.height;
    }

    if ([[UIDevice currentDevice] userInterfaceIdiom] == userInterfaceIdiom && [[UIScreen mainScreen] scale] == scale && mainScreenHeight == height)
    {
        return YES;
    }
    else
    {
        return NO;
    }
}

Also here are the accompanying OperatingSystem class methods:

+ (NSString *) currentOperatingSystemVersion
{
    return [[UIDevice currentDevice] systemVersion];
}
+ (BOOL) operatingSystemVersionLessThanOrEqualTo:(NSString *) operatingSystemVersionToCompare
{
    return ([[self currentOperatingSystemVersion] compare: operatingSystemVersionToCompare options:NSNumericSearch] != NSOrderedDescending);    
}
Ser Pounce
  • 14,196
  • 18
  • 84
  • 169
-1

Put below lines in prefix.pch

#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 (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");
}

However, I would say use one storyboard for all iPhones by learning autolayout.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
  • 2
    Use a `switch` statement. Otherwise, for an iPad, you end up evaluating that huge pile of code four times (once per `if` statement). And the code will fail under iOS 8 when in landscape. – rmaddy Sep 26 '14 at 23:32
  • That's a rather stupid approach. It will break when the next iPhone is released and the code mistakenly thinks it's an iPad. – gnasher729 Sep 27 '14 at 12:57
  • 1
    @gnasher729 : also let me know **YOUR BETTER APPROACH** – Fahim Parkar Sep 27 '14 at 13:01