Reputation: 29094
I am trying to migrate my app for iphone 5. I have already seen the other questions in stackoverflow and still facing the some problems in correctly showing it.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
_backgroundimageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,500)];
[_backgroundimageView setImage:[UIImage imageNamed:@"[email protected]"]];
} else {
// code for 3.5-inch screen
[_backgroundimageView setImage:[UIImage imageNamed:@"image1.png"]];
}
The size I have set for backgroundimageView is 320 x370 in the size inspector and the image size of [email protected] has a size of 640x 1136 and of image1.png is 640x733.So, for 3.5 inch screen, it should show normally and for 4-inch screen, it should resize accordingly.
But the problem is that for 4-inch screen, it doesn't resize and ends up showing me the same as 3inch screen with some white border to cover the remaining area.
Need some guidance to solve it. Thanks.. Can point out the mistake i am doing...
Upvotes: 0
Views: 170
Reputation: 1542
Why you are again allocating backgroundimageView
for iPhone 5 resolutions. Just use the same IBOutlet of backgroundimageView
and modify the frame and image of it.
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
_backgroundimageView.frame = CGRectMake(0,0,320,460);
[_backgroundimageView setImage:[UIImage imageNamed:@"[email protected]"]];
} else {
// code for 3.5-inch screen
_backgroundimageView.frame =CGRectMake(0,0,320,370);
[_backgroundimageView setImage:[UIImage imageNamed:@"image1.png"]];
}
Upvotes: 1
Reputation: 7102
I think content mode of your imageview is center so try this for your imageview
[_backgroundimageView setContentMode:UIViewContentModeScaleAspectFill]
Upvotes: 0
Reputation: 1097
Default image name must be "[email protected]" (not [email protected]) try renaming the default image name and check again, you will get right screen size.
Also you can check iphone5 by macros.
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0f)
Upvotes: 0