简体   繁体   English

将最大宽度设置为约束

[英]Set max width to constraint

在此输入图像描述

I have rectangle with four constraints. 我有四个约束的矩形。 All works ok, but on ipad this rectangle is too big. 一切正常,但在ipad上这个矩形太大了。 So is there a way to set max margin for constraints. 那么有没有办法为约束设置最大余量。 i tried set Relation value to "gather then" or "less then" but it not works. 我尝试将“关系”值设置为“收集然后”“少于”但它不起作用。

Constraints have a field for priority. 约束具有优先级的字段。 This is a case where you want to use that. 这是您想要使用它的情况。 It looks like you want your rectangle to be centered, so I would recommend the following constraints: 看起来你想要你的矩形居中,所以我建议以下约束:

  1. CenterX of rectangle equal to CenterX of superView. 矩形的CenterX等于superView的CenterX。 Priority 1000 优先级1000
  2. CenterY of rectangle equal to CenterY of superView. 矩形的CenterY等于superView的CenterY。 Priority 1000 优先级1000
  3. Width of rectangle less than or equal to maximum size you want for iPad. 矩形宽度小于或等于iPad所需的最大尺寸。 Priority 1000 优先级1000
  4. Height of rectangle less than or equal to maximum size you want for iPad. 矩形的高度小于或等于iPad所需的最大尺寸。 Priority 1000 优先级1000
  5. Vertical constraint for distance from top of superView. 距离superView顶部的距离的垂直约束。 Priority 750 优先级750
  6. Horizontal constraint for distance from leading edge of superView. 距离superView前沿距离的水平约束。 Priority 750 优先级750

On iPhones, all of the constraints will be met because the rectangle will easily be smaller than the maximum size for iPad. 在iPhone上,所有约束都将得到满足,因为矩形很容易小于iPad的最大尺寸。

On iPads, the higher priority width and height constraints will keep the rectangle from growing too big, and Auto Layout will allow the top and leading edge constraints to be broken to make that possible, but it will make the rectangle as big as possible to come as close as possible to meeting the horizontal and vertical offsets. 在iPad上,较高优先级的宽度和高度限制将使矩形不会变得太大,并且自动布局将允许打破顶部和前缘约束以实现这一点,但它将使矩形尽可能大尽可能接近水平和垂直偏移。

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

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