简体   繁体   English

AutoLayout圆形UIButton-等效的垂直和水平大小

[英]AutoLayout Circular UIButton - Equivalent Vertical and Horizontal Size

How do you make a UIButton's vertical distance equivalent to a UIButton's horizontal distance in AutoLayout. 在AutoLayout中,如何使UIButton的垂直距离等于UIButton的水平距离。

Using Visual Format Language, I can currently make all UIButtons have the equivalent height or width, but I don't know how to specify those to be the same. 使用视觉格式语言,我目前可以使所有UIButton具有相同的高度或宽度,但是我不知道如何指定相同的高度或宽度。

I also do not want this distance to be predefined which I know is possible through setting metrics. 我也不希望这个距离是预定义的,我知道可以通过设置度量标准来实现。

You can't use vfl for this. 您不能为此使用vfl。

You have to use the method... 您必须使用该方法...

AddConstraintForItem:attribute:relation:toItem:attribute:multiplier:constant. AddConstraintForItem:attribute:relation:toItem:attribute:multiplier:constant。

Or something like that anyway. 还是类似的东西。

Both items can be the same and the two attributes set one to width and one to height. 两项可以相同,并且两个属性将一个设置为宽度,将一个设置为高度。

Figured out a solution to this. 找出解决方案。 You can't use Visual Format Language, but rather need to use NSLayoutConstraint constraintWithItem 您不能使用视觉格式语言,而需要使用NSLayoutConstraint ConstrainintWithItem

NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:forwardButton attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:forwardButton attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0];
[self.view addConstraint:constraint];

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

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