简体   繁体   English

当我们使用不同大小和类型的屏幕时,如何在iOS中设置UI控件的宽度和高度限制?

[英]How setting width and height constraints of UI controls in iOS works when we use different size and types of screen?

I am learning Auto-layout in iOS, how setting margin or setting width and height of control will scale according to different size of iPhone and iPad sizes. 我正在学习iOS中的自动版式,如何设置边距或设置控件的宽度和高度如何根据iPhone和iPad尺寸的不同而缩放。

For example, if I set image of 200 by 200 in iPhone, will it not look very small as compared to iPad, even iPhone 5S is much smaller than iPhone 6S Plus. 例如,如果我在iPhone中将图像设置为200 x 200,与iPad相比看起来会不会很小,即使iPhone 5S也比iPhone 6S Plus小得多。

I am missing something important related to Auto-layout? 我缺少与自动布局相关的重要信息吗?

We always use 'size class' to adapt iPhone and iPad. 我们始终使用“尺寸等级”来适应iPhone和iPad。 So if you want to have a image of 200 by 200 in iPhone just setting in wC-hA size, then change size to wR-hR to set 300*300 for iPad. 因此,如果您想在iPhone中以200 x 200的比例仅设置wC-hA尺寸,则将尺寸更改为wR-hR即可为iPad设置300 * 300。

在此处输入图片说明

You maybe not want to set a absolute width to image, the aspect ratio constraint is a good way to set relative width: 您可能不想为图像设置绝对宽度,长宽比约束是设置相对宽度的好方法:

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

It will set the button's width equal to a quarter of superview's width. 它将设置按钮的宽度等于超级视图宽度的四分之一。

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

相关问题 如何为指定的屏幕尺寸提供单独的高度和宽度约束,例如为iPhone和iPad提供不同的约束? - how to give separate height and width constraint for specified screen size for eg giving different constraints for iphone and ipad? 如何使用不同屏幕的约束来调整视图的高度和宽度? - How to resize height & width of the view using constraints for different screen? 如何在iOS中获取屏幕宽度和高度? - How to get the screen width and height in iOS? 尺寸类不支持IOS中常规宽度和常规高度的UI元素 - Size classes not support UI elements for regular width and regular height in IOS ios - 根据屏幕尺寸调整按钮宽度和高度 - ios - Adjust button width and height based on screen size 如何为不同大小的类别设置子视图高度限制 - How to set subview height constraints for different size classes 宽度/高度按钮相等的网格上的iOS约束导致位置和大小变化 - iOS Constraints on Grid of Equal Width/Height Buttons cause positioning and size to vary 设置宽度和高度约束时,UIImageView将位于单元格的左上方。 - UIImageView going to top left of cell when setting width and height constraints. 如何在 iOS 中动态更改 UI 控件的大小? - How do I dynamically change the size of UI controls in iOS? 设置不同屏幕尺寸的约束时出现问题 - Problem with setting up constraints for different screen sizes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM