[英]How to make an object adapt to another size when the app runs in another device. (swift)
I'm new to programmimg and Swift. 我是Programmimg和Swift的新手。 And I want to know how to make an object adapts it's size if I run the app in a different device.
我想知道如果我在其他设备上运行应用程序,如何使对象适应其大小。
For example, 例如,
I have a view that I setup like this: 我有一个这样设置的视图:
var myView = UIView(frame: CGRectMake(0, 0, view.frame.width, 165) var myView = UIView(frame:CGRectMake(0,0,view.frame.width,165)
I want it to have 165 of height in iPhone 6 and 6s, but what should I do if I want it to have, for example, 100 in iPhone 5? 我希望它在iPhone 6和6s中具有165的高度,但是如果我希望它在iPhone 5中具有100的高度,该怎么办?
Thanks so much. 非常感谢。 I know this is a dumb question.
我知道这是一个愚蠢的问题。
You shouldn't create the view programmatically, you should use the story board. 您不应该以编程方式创建视图,而应该使用情节提要。 Create a UIview and give it the constraints that you want, with these constraints it auto-sizes to all iPhone devices.
创建一个UIview并为其提供所需的约束,并根据这些约束自动为所有iPhone设备调整大小。 This makes it easier for you!
这使您更轻松! Hope this helped!
希望这对您有所帮助!
对于不喜欢故事板并且喜欢以编程方式做所有事情的任何人,请尝试:
CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.