Usage of ToLayoutConstraints
See original GitHub issueThis version of AddConstraints permits the use of both simple and advanced constraints in the same call. If you remove ToLayoutConstraints it will not work anymore.
Advanced constraints methods use more than one Constraint object to achieve the result.
public static void AddConstraints(this UIView view, params object[] fluentLayouts)
{
view.AddConstraints((fluentLayouts
.Where(fluent => fluent != null)
.OfType<FluentLayout>()
.SelectMany(fluent => fluent.ToLayoutConstraints())
).Concat(fluentLayouts
.OfType<IEnumerable<FluentLayout>>()
.SelectMany(fluent => fluent.SelectMany(fluent2 => fluent2.ToLayoutConstraints()))
).ToArray());
}
public static IEnumerable<FluentLayout> WithSameRectOf(this UIView view, UIView parent, nfloat? margin = null)
{
return
view.FullWidthOf(parent, margin)
.Concat(view.FullHeightOf(parent, margin))
.Concat(view.AtTopLeftOf(parent, margin));
}
Sample usage:
ContentView.AddConstraints(
title.AtLeftOf(ContentView, 2.5f),
title.AtTopOf(ContentView, ItemSize.Width + 2.5f),
image.WithSameRectOf(imageSvg)
);
Without this extension methods, WithSameRectOf can not be used.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Working with Constraints in Interface Builder
There are three main options for setting up Auto Layout constraints in Interface Builder: You can control-drag between views, you can use ...
Read more >What's with Constraints in SwiftUI?
SwiftUI doesn't use layout constraints. ... Here are some examples how you can achieve specific layouts with those modifiers compared to ...
Read more >Build a responsive UI with ConstraintLayout
ConstraintLayout lets you create large, complex layouts with a flat view hierarchy—no nested view groups. It's similar to RelativeLayout in that all views ......
Read more >How to activate multiple Auto Layout constraints using ...
NSLayoutConstraint has a class method called activate() that activates multiple constraints at once, which should allow Auto Layout to update ...
Read more >Working With Auto Layout and Layout Anchors
NSLayoutDimension : This subclass is used to create layout constraints that describe the width and height of a view. NSLayoutXAxisAnchor : This subclass...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d suggest, instead of adding non-constructive comments, that you made a PR so your own changes could be merged in upstream. If you don’t want to do that keep using your own stuff.
It is dormant until you really remove the code. If you remove it i will wake it up fast!!!