Xcode 4.5 background image iPhone 4, 4s, 5

后端 未结 3 2085
轻奢々
轻奢々 2021-02-04 18:29

I have in my viewController.m written the background code:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@\"image.png\"]];
         


        
3条回答
  •  自闭症患者
    2021-02-04 19:08

    iPhone 5 is retina, just like iPhone 4 and 4S, and the @2x-image will be used automatically for all these devices. It's only the startup-image that is called "-568h@2x" for iPhone 5. You need to write some code to use a different image, something like this would work:

    NSString *filename = @"image.png";
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    if (screenRect.size.height == 568.0f)
        filename = [filename stringByReplacingOccurrencesOfString:@".png" withString:@"-568h.png"];
    
    imageView.image = [UIImage imageNamed:filename];

提交回复
热议问题