Using Cirrious.FluentLayout how can I add an aspect ratio constraint?
Asked
Active
Viewed 78 times
0
-
1There are several examples of using a `multiplier` to get a ratio effect https://github.com/FluentLayout/Cirrious.FluentLayout/search?q=multiplier&unscoped_q=multiplier – Saamer Aug 23 '20 at 17:11
1 Answers
0
I created an extension method that does the trick.
public static FluentLayout WithAspectRatio(this UIView view, nfloat ratio) =>
view.Height().EqualTo().WidthOf(view).WithMultiplier(ratio);
Now it's as simple as doing this to get a 1:1 ratio.
View.AddConstraints(
...
whiteBackground.WithAspectRatio(1f)
...);

Hackmodford
- 3,901
- 4
- 35
- 78