简体   繁体   English

当应用程序在其他设备上运行时,如何使对象适应其他大小。 (迅速)

[英]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.

相关问题 尝试在iOS设备上运行应用程序时出错。 它在模拟器上运行 - Error trying to run app on iOS device. It runs on emulator Swift:如何使UILabel从另一个UIlabel继承字体大小? - Swift : How to make UILabel inherit font size from another UIlabel? 当应用程序在我的设备(iPhone 6)上快速运行时,“没有可用的源1类型” - 'No available types for source 1' when the app runs on my device(IPhone 6) swift “此代码适用于与此设备不兼容的应用。” - “This code is for an app that is not compatible with this device.” phonegap iOS应用程序可在模拟器上运行,但不能在设备上运行。 如何调试 - phonegap iOS app working on simulator but not in device. How to debug 设备上另一个应用程序的CFBundleVersion - CFBundleVersion of another app on the device 设备大小快速变化时,如何获取子视图的当前大小? - how to get current size of a subview when device size changes in swift? 在Xcode中使用自由格式的模拟尺寸时,如何使屏幕适应? - How to make the screen adapt when you use a freeform simulated size in Xcode? 如何使SWRevealViewController迅速成为另一个控制器的子级 - How to make SWRevealViewController a child of another controller in swift 如何在 SwiftUI 中查看另一个视图的大小 - How to make view the size of another view in SwiftUI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM