question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Usage of ToLayoutConstraints

See original GitHub issue

This 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:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Cheesebaroncommented, Dec 19, 2016

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.

0reactions
softlioncommented, Dec 7, 2018

It is dormant until you really remove the code. If you remove it i will wake it up fast!!!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found