Easer Liu
Easer Liu

Reputation: 17

What is the code when I want to show a @2x image in app

Today when I search some information about @1x @2x @3x something confuses me are these only used as app icon? Because most messages always give me the example of the icon. and If it can be used in app view, how is the code? like this?

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

Then, iOS will change @1x and @2x itself? OR I need to code like this:

#define deviceIsIPhone5 ([UIScreen mainScreen].applicationFrame.size.height == 568 ? YES : NO)
    if (deviceIsIPhone5) 
{
    self.backgroundImage.image = [UIImage imageNamed:@"[email protected]"];
} 
else
{
    self.backgroundImage.image = [UIImage imageNamed:@"background.png"];
}

Upvotes: 0

Views: 122

Answers (2)

Ajjjjjjjj
Ajjjjjjjj

Reputation: 675

no need to care about 2x,3x and png. just enter image name only. ios will automatically check image to use according to screen dimensions.

self.backgroundImage.image = [UIImage imageNamed:@"background"];

Upvotes: 0

elk_cloner
elk_cloner

Reputation: 2149

You don't have to think about @2x @3x.iOS automatically handles it.

All you need to care about is to put right size image into the right box(.xcassets) if you want to show image properly in all iOS devices.

Upvotes: 1

Related Questions