user1625435
user1625435

Reputation: 153

xcode convert iPhone to iPad

help please. my code that change UIImageView is:

- (void) viewDidLoad {

background.image = [UIImage imageNamed:@"myImage.png"];

}

It works good on iPhone and also on iPad but, how can I change "myImage.png" to "myImageHD.png" when I will run this app on my iPad???? I just need to show myImageHD if my app will run on iPad. IT CAN BE DONE WITH XIB FILE, BUT I NEED WITH CODE TO FIX IT. To detect if app run on iPad, and show myImageHD. Thanks.

Upvotes: 2

Views: 316

Answers (4)

DD_
DD_

Reputation: 7398

NSString *deviceType = [UIDevice currentDevice].model;

if([deviceType isEqualToString:@"iPhone"])
{
     // it's an iPhone
}

this will help you, but i dont think that it a good try using same XIB and changing the image only! regards

Upvotes: 1

rahul sharma
rahul sharma

Reputation: 121

Try this one

 - (void) viewDidLoad {

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
        background.image = [UIImage imageNamed:@"myImageHD.png"];
    }
    else{
        background.image = [UIImage imageNamed:@"myImage.png"];
    }
}

Upvotes: 3

iDev
iDev

Reputation: 23278

Do this,

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
   background.image = [UIImage imageNamed:@"myImage.png"];
} else { //UIUserInterfaceIdiomPad is for iPad
   background.image = [UIImage imageNamed:@"myImageHD.png"];
}

Another way to do this would be,

if ([(NSString*)[UIDevice currentDevice].model isEqualToString:@"iPad"] } { //As per the below comment, for iPad simulator the string will be "iPad simulator"
    background.image = [UIImage imageNamed:@"myImageHD.png"];
} else {
    background.image = [UIImage imageNamed:@"myImage.png"];
} 

UI_USER_INTERFACE_IDIOM() also can be used to check if the current device is iPad or iPhone. Instead of [[UIDevice currentDevice] userInterfaceIdiom] in the above if condition, you can use UI_USER_INTERFACE_IDIOM() also.

Upvotes: 4

Siba Prasad Hota
Siba Prasad Hota

Reputation: 4789

Try to use below code

- (void) viewDidLoad {

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
background.image = [UIImage imageNamed:@"myImageHD.png"];
}
else
background.image = [UIImage imageNamed:@"myImage.png"];

}

Upvotes: 2

Related Questions