Demo of aspect ratio constraint
There is a UI layout feature:
One view’s size keeps 16:9 ratio, but will extend its size with its super view.
The demo uses several constraints to implement:
-
Required constraints:
- C1, Align Center X, to super view
- C2, Align Center Y, to super view
- C3, Aspect ratio 16:9, to super view
-
Mid priority constraints:
- C4, Leading space, to super view, value is 50
- C5, Top space, to super view, value is 50
- C6, Trailing space, to super view, value is 50
- C7, Bottom space, to super view, value is 50
-
Low priority constraints:
- C8, Equal width, to super view, value is -100
- C9, Equal height, to super view, value is -100
C1, C2, C3, and C7’s priority is 1000 (default value).
C4, C5, C6, and C7’s priority is 750.
C8 and C9’s priority is 490. It may be other value, but MUST be lower than 500.
Source code is here.