做这个,
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]
上面的 if 条件,你也可以使用UI_USER_INTERFACE_IDIOM()
。