问题
I've added a Default-568h@2x.png launch image to my app. The app needs to display a second launch image after the "real" launch image. Because the UIImage imageNamed: method doesn't automatically load the taller image the way it automatically loads retina images, I've added some code to detect the screen size and display the correct image:
-(void)pickRightImage
{
CGSize result = [[UIScreen mainScreen] bounds].size;
UIImageView *imgv = [self loadingImage];
UIImage *img;
if(result.height == 480)
{
img = [UIImage imageNamed:@"loading_screen.png"];
} else if([UIScreen mainScreen].scale == 2.f && result.height == 568) {
// iPhone 5
img = [UIImage imageNamed:@"loading_screen-568h@2x.png"];
}
[imgv setImage:img];
}
The imageView takes up the whole screen in the NIB, which is named MainWindow, and I have selected the checkbox named "Full Screen At Launch" However, the image never takes up the whole screen. (Although the launch image does.) The second image is letter boxed just as if it were a smaller image, and I had never included the tall launch image.
Is there anyway to programmatically display a full screen image on the 4 inch iphone5? Why is my image always resized?
回答1:
I tested this on the main view controller. Also, on Target > Summary > Status Bar > Visibility check "Hide during application launch".
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *iv = [[UIImageView alloc] initWithFrame:self.view.bounds];
iv.image = [UIImage imageNamed:@"Second-default568h@2x.png"];
[self.view addSubview:iv];
}
回答2:
[UIImage imageNamed:]
will take care of adding the @2x
for you. So you should just specify
img = [UIImage imageNamed:@"loading_screen-568h.png"];
It's also useless to test both a 4" screen AND the Retina criteria (scale = 2). All devices that have a 4" screen (568px tall) are Retina displays, so you can assume that if height == 568, the user has an iPhone 5 : replace
if ([UIScreen mainScreen].scale == 2.f && result.height == 568)
with
if ([UIScreen mainScreen].bounds.size.height == 568)
and you're good.
来源:https://stackoverflow.com/questions/12643735/cant-display-640x1136-image-on-iphone5