如何找出用户使用的设备?我目前使用的代码是:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if(screenBounds.size.height == 568){
NSLog(@"User is using an iPhone 5s, 5c, or 5");
}
else{
NSLog(@"User is using an iPhone 4s or earlier");
}
还有哪些其他数字可以归还,它会是什么设备?例如,我希望这样的事情:
screenBounds.size.height == 568
将是iPhone5 / 5s / 5c
screenBounds.size.height == 480
将是iPhone 4 / 5s
screenBounds.size.height > 570
将成为iPad
等等。我将使用它来根据用户使用的设备更改nib
文件,这样我就不必移动每个按钮,图像,标签或任何其他{{1 }}
我没有使用自动布局,因为我还希望根据用户使用的设备进行更多自定义。
答案 0 :(得分:1)
检查设备类型:
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad )
{
// You are using iPad
return YES;
}
else if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomiPhone )
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if(screenBounds.size.height == 568){
NSLog(@"User is using an iPhone 5+");
} else{
NSLog(@"User is using an iPhone 4s-");
}
}