做到这一点,
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
background.image = [UIImage imageNamed:@"myImage.png"];
} else { //UIUserInterfaceIdiomPad is for iPad
background.image = [UIImage imageNamed:@"myImageHD.png"];
}
另一种方式来做到这一点是,
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()
也可以用来检查当前设备是iPad或iPhone。在上面的条件中,而不是[[UIDevice currentDevice] userInterfaceIdiom]
,也可以使用UI_USER_INTERFACE_IDIOM()
。
第二种方法是不适合,如果你想在模拟器,因为该模型串会在模拟器 –
是的“iPad”在设备和“iPad模拟器” @Deepak,谢谢。我早先没有想过。在答案中添加了评论。 – iDev