Reputation: 31
I use this code in "viewDidLoad" to check if app is running on iPhone 5 or regular iPhone.
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
[_backgr setImage:[UIImage imageNamed:@"usefull_i4.png"]];
[scrollView setFrame:CGRectMake(16, 69, 291, 349)];
[_backgr setFrame:CGRectMake(0, 0, 320, 480)];
}
if(result.height == 568)
{
// iPhone 5
[_backgr setImage:[UIImage imageNamed:@"usefull_i5.png"]];
[scrollView setFrame:CGRectMake(15, 111, 295, 349)];
[_backgr setFrame:CGRectMake(0, 0, 320, 568)];
}
}
It doesn't work. :( Only if I change !here from iPhone 3.5 to iPhone 4, this code work. 1
Also I use this code for another ViewController and works great.. I don't use Autolayout.
Upvotes: 0
Views: 224
Reputation: 19418
Try this macro : (in .pch file)
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
Example :
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if(IS_IPHONE_5)
{
// code
}
}
Upvotes: 1