如何使用 FluentLayout 添加纵横比约束

How to add aspect ratio constraint with FluentLayout

如何使用 Cirrious.FluentLayout 添加纵横比约束?

我创建了一个可以解决问题的扩展方法。

public static FluentLayout WithAspectRatio(this UIView view, nfloat ratio) =>
            view.Height().EqualTo().WidthOf(view).WithMultiplier(ratio);

现在,获得 1:1 比率就这么简单。

View.AddConstraints(
                    ...
                    whiteBackground.WithAspectRatio(1f)
                    ...);