本文介绍了如何在iOS中设置视图的最大宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序有一个基本的登录屏幕,一个外框以及其中的一些文本字段和按钮.我将框设置为填满整个屏幕.但是,在某些设备上,此框太大.如何设置视图的最大宽度和高度?
My app have a basic login screen, an outer box and in it, some text fields and buttons. I set the box to fill the screen. However, on some devices this box will be too big. How do I set maximum width and height to a view?
推荐答案
您可以使用自动布局约束,以使框适应屏幕尺寸,但不超过给定的宽度和高度.为此,在宽度和高度上设置小于或等于"约束.
You can use auto-layout constraints so that the box adapts to the screen size, but does not exceed a given width and height. To do this, set a "less than or equal to" constraint on the width and height.
- 在框中添加顶部,底部,前导,尾随,宽度和高度约束.
- 将顶部,底部,前导和尾随约束的优先级设置为高(750).
- 将宽度和高度约束的关系设置为小于或等于(≤).默认值为等于.
- 将宽度和高度约束的优先级设置为必需(1000).
- 将宽度和高度约束的常数设置为您要使框成为的最大大小.
- Add top, bottom, leading, trailing, width and height constraints to the box.
- Set the priority of the top, bottom, leading and trailing constraints to High (750).
- Set the relation for the width and height constraints to Less Than or Equal (≤). The default value is Equal.
- Set the priority of the width and height constraints to Required (1000).
- Set the constant of the width and height constraints to the maximum size you want the box to be.
这篇关于如何在iOS中设置视图的最大宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!