简体   繁体   English

某些屏幕尺寸的Swift ios隐藏按钮

[英]Swift ios hide button on certain screen sizes

I wonder how I can hide a button on certain screen sizes. 我想知道如何在某些屏幕尺寸上隐藏按钮。 What I am trying to do is to show a button when the app is running on a iphone 我想要做的是在应用程序在iphone上运行时显示一个按钮

Right now I have setup size classes, setting a width/height to 0 on a certain size class (ipads). 现在我有设置大小类,在特定大小类(ipads)上将宽度/高度设置为0。 This works, but is there any other way to do it? 这有效,但有没有其他方法可以做到这一点?

Thanks 谢谢

The best way is actually to use size classes, as it is only dependant on the actual screen size. 最好的方法实际上是使用大小类,因为它只取决于实际的屏幕大小。 It would be bad if the size of the app is like an iPhone, but runs on an iPad in split view mode 如果应用程序的大小像iPhone一样,但在分割视图模式下在iPad上运行会很糟糕

You can use UIDevice.currentDevice().model , which is equal to "iPhone" if the app is running on an iPhone or "iPad" if the app is running on an iPad. 您可以使用UIDevice.currentDevice().model ,如果应用程序在iPhone上运行,则等于“iPhone”,如果应用程序在iPad上运行,则等于“iPad”。

Code snippet: 代码段:

var model = UIDevice.currentDevice().model
if model == "iPhone" {
thatbutton.hidden = false
} else {
thatbutton.hidden = true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM