I have two different views for the iphone 4/4S and the iphone 5/5s/5c. I need to display the correct view depending on the model of the phone. Could someone please tell me how you code the app to check for phone model and then display either the 3.5 or 4 inch view? Thanks a lot!
Asked
Active
Viewed 88 times
0
-
Could Autolayout solve your issues? – Larme Apr 17 '14 at 09:10
-
@Larme How do i put auto layout on? – Juliane Kakoli Apr 17 '14 at 09:12
3 Answers
3
I have created a macro in my app, and use it throught to check for device:
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
Use it in the following way:
if (IS_IPHONE_5) {
//iPhone 5x specific code
} else {
//iPhone 4x specific code
}
Note: My deployment target is only iPhone, and no other iOS devices, so the code is safe, unless future versions of the iPhone have other dimensions.

n00bProgrammer
- 4,261
- 3
- 32
- 60
-
Have you tried it? Works absolutely fine on both my iPhone 4S, and iPhone 5. – n00bProgrammer Apr 17 '14 at 10:00
-
Sorry, my mistake, just tried, it works in both modes. I've removed my comment. – Vlad Papko Apr 17 '14 at 10:08
1
You can use https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html
Also refer the link Determine device (iPhone, iPod Touch) with iPhone SDK
Refer the link: https://gist.github.com/Jaybles/1323251. You need to include UIDeviceHardware.h & UIDeviceHardware.m files in your project
UIDeviceHardware *h=[[UIDeviceHardware alloc] init];
[self setDeviceModel:[h platformString]];
[h release];
Hope this helps.

Community
- 1
- 1

user2071152
- 1,161
- 1
- 11
- 25
1
You could write category to UIDevice for checking device screen height:
// UIDevice+Utils.h
@interface UIDevice (Utils)
@property (nonatomic, readonly) BOOL isIPhone5x;
@end
// UIDevice+Utils.m
@implementation UIDevice (Utils)
@dynamic isIPhone5x;
- (BOOL)isIPhone5x {
BOOL isIPhone5x = NO;
static CGFloat const kIPhone5Height = 568;
if (self.userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
CGRect screenBounds = [UIScreen mainScreen].bounds;
if (screenBounds.size.width == kIPhone5Height || screenBounds.size.height == kIPhone5Height) {
isIPhone5x = YES;
}
}
return isIPhone5x;
}
@end
// Usage
if ([UIDevice currentDevice].isIPhone5x) {
// Use 4 inch view here
} else {
// Use 3.5 inch view here

Vlad Papko
- 13,184
- 4
- 41
- 57