skip to Main Content

I have just created a png image that id like to use in my app as a background.

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

Here is the code which sets that background that works. I just registered for the iOS dev program so now i will be able to test ad hoc on my devices. I was wondering how to ‘override’ this image so that it rasterizes well on the iPad.

The dimensions for the original photoshop jpg are about 500 height 350 width which i find fits perfectly as an iPhone background. The dimensions for an HD image i hear is on average; 1920 height and 1080 width but I am using a virtual box so my screen space is a tad meh. Anyway how to I override images for the iPad bkg?

Thanks

3

Answers


  1. You should bundle the images for iPad as well. Now at run time you can check if the device is iPAd then you should load the images accordingly.

    Using asset bundle (xcassets), you can configure different images for different iOS devices and it will load proper image at run time.

    Login or Signup to reply.
  2. You can rename image files for different devices as mentioned below and iOS will automatically take relevant image.

    bg_tile.png - For non ratina iPhone
    [email protected] - For ratina iPhone
    bg_tile~ipad.png - For non ratina iPad
    bg_tile@2x~ipad.png - For ratina iPad
    

    If you image size is big enough, I would suggest you not use

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

    instead use background UIImageView and set its image property.

    self.view.backgroundImageView = [UIImage imageNamed:@"bg_tile.png"];
    
    Login or Signup to reply.
  3. You can use [[UIDevice currentDevice] userInterfaceIdiom] to determine whether you’re running on an iPhone/iPod touch or an iPad.

    There’s often no need to determine directly whether you’re on a retina display because UIImage handles that automatically when you use imageNamed and append “@2x” to your high resolution image file names (see Supporting High-Resolution Screens in the Drawing and Printing Guide for iOS).

    If you really need to know which resolution the screen has, use UIScreen’s scale method.

    +(BOOL)isPad
    {
    #ifdef UI_USER_INTERFACE_IDIOM
        return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
    #endif
        return NO;
    }
    
    +(BOOL)hasRetinaDisplay
    {
        // checks for iPhone 4. will return a false positive on iPads, so use the above function in conjunction with this to determine if it's a 3GS or below, or an iPhone 4.
        if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2)
            return YES;
        else
            return NO;
    }
    

    Hope this will help to you..

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search