我在另一篇文章中找到了代码。
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
}
else
{
//iphone 3.5 inch screen
}
}
else
{
//[ipad]
}
这篇文章是5年前的文章代码。 我认为它太旧了。 因为它不兼容iPhone 10。
请告诉我允许灵 active 的最新代码。
最佳答案
这就是我在我的应用程序中使用的;这是一种享受:
if UIDevice().userInterfaceIdiom == .phone && UIScreen.main.nativeBounds.height == 2436 {
// Device is iPhone X
}else if UIDevice().userInterfaceIdiom == .pad && UIScreen.main.nativeBounds.height == 1668 {
// Device is iPad Pro 10.5' X
}else{
//Device is something else
}
如果您转到Apple Developer Documentation Archive ,您可以选择要用于检测特定设备的属性。如果存在多种情况,也许 switch
语句会更合适。
关于ios - 如何根据iPhone 8、X或iPad的屏幕尺寸更改代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51131020/