本文介绍了"宽度等于高度"约束在Interface Builder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能找到一种方法来创建一个广场的约束,这意味着在Interface Builder的宽度等于高度。我想这是可能的编程方式添加这样的限制。有什么我可以做IB?也许我只是没有看到呢?这似乎微不足道,但我找不到它。

I can't find a way to create a 'square' constraint, meaning 'width equals height' in Interface Builder. I guess it's possible to add such constraint programmatically. Is there something I can do in IB? Maybe I just don't see it? It seems trivial, yet I can't find it.

推荐答案

更新X $ C $ç5.1b5

按Ctrl +从视图中单击并拖动和释放,而指针所在的视图。选择宽高比。其中第一和第二项是视图它会创建一个约束

Ctrl+click and drag from a view and release while the pointer is over the view. Select "Aspect Ratio". It will create a constraint where the first and second item is the view.

X $ C $在C之前5.1

您不能因为宽度/高度编辑缺乏领域涉及到另一个属性或设置比:

You can't because the width/height editor lacks the fields to relate to another property or set the ratio:

因此​​,你不能EX preSS在Interface Builder以下code:

Therefore, you can't express the following code in Interface Builder:

CGFloat ratio = 1.0;
NSLayoutConstraint *constraint = [NSLayoutConstraint
    constraintWithItem:myView
    attribute:NSLayoutAttributeWidth
    relatedBy:NSLayoutRelationEqual
    toItem:myView
    attribute:NSLayoutAttributeHeight
    multiplier:ratio
    constant:0];
constraint.priority = 1000;
[myView.superview addConstraint:constraint];

这篇关于"宽度等于高度"约束在Interface Builder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:19