使用视觉格式语言的“宽度等于高度"约束 [英] “Width equals height” constraint using visual format language

查看:102
本文介绍了使用视觉格式语言的“宽度等于高度"约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了添加等于其超级视图高度的宽度,我们可以按照

In order to add width equals to its superview height we can do following

NSLayoutConstraint(item: view, attribute: .width, relatedBy: .equal, toItem: view.superview, attribute: .height, multiplier: 1, constant: 0)

或者我们可以通过界面生成器完成

or we can do it from interface builder

但是如何使用VFL进行同样的操作?

But how can I do the same using VFL?

推荐答案

来自

表示法优先选择良好的可视化效果,而不是完整性 可表达性.对实际用户有用的大多数约束 界面可以使用视觉格式语法表示,但是有 一些不能.一个无法表达的有用约束是 固定的宽高比(例如,imageView.width = 2 * imageView.height).要创建这样的约束,您必须使用 constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:.

The notation prefers good visualization over completeness of expressibility. Most of the constraints that are useful in real user interfaces can be expressed using visual format syntax, but there are a few that cannot. One useful constraint that cannot be expressed is a fixed aspect ratio (for example, imageView.width = 2 * imageView.height). To create such a constraint, you must use constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:.

宽度等于高度"是比率(等于1).所以这是不可能的.

"Width equals Height" is a ratio (to 1). So it's not possible.

这篇关于使用视觉格式语言的“宽度等于高度"约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆