phpN00b
phpN00b

Reputation: 138

Can't Seem To Distinguish Between iPad Retina or Standard (Original)

I currently use a code to alter the picture of my cocos2d layer menu background, so that it fits inside the boundary of the screen...

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
        //iPhone Classic (3gs)
        NSLog(@"Currently running iPhone Classic Code Block----------");
        background.scale = 0.5; // May need changing once using retina mode!!!
    }
    else if(result.height == 568)
    {
        // iPhone 5
        NSLog(@"Currently running iPhone 5 Code Block---------");
        background.scale = 0.6; // May need changing once using retina mode!!!
    }
}

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 1024)
    {
        //iPad Classic
        NSLog(@"Currently running iPad Classic Code Block--------");
        background.scale = 1.2;
    }
}

However well this works, I cannot seem to distinguish between the iPad retina or the original...

They both report their heights as 1024, but when running side by side the back ground is clearly half the size of the other. If I increase the background.scale it'll fit the one, but then two big for the other...

How can I rectify this? thanks...

Upvotes: 0

Views: 80

Answers (2)

Mawoon
Mawoon

Reputation: 1045

Here is the simple code to detect retina and standard display:

if([UIScreen mainScreen].scale>1.0)
{
nslog(@"Retina");
}else
{
nslog(@"NONRetina");
}

Upvotes: 1

Marc
Marc

Reputation: 6190

To differentiate between retina and non retina you should use the scale property of the screen.

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0) {
    // It's retina!
}

Since this property was added in a later version of iOS, you should ask if the property exists (hence the respondsToSelector)

Upvotes: 1

Related Questions