While using Cassowary constraint-fixing toolkit, the bridge offers support for Auto Layout, Apple’s first-party mechanism for building constraint-based designs. Auto Layout includes many, a variety of APIs featuring, however, and until lately only a number of probably the most versatile and broadly-used ones were obtainable in the bridge.
Now, we’re adding support for 2 recent inclusions in Auto Layout. In software development company , Apple introduced two new classes made to simplify adding layout constraints to sights: NSLayoutAnchor and UILayoutGuide. This reduced the quantity of code needed to produce simple, edge-moored designs that scale correctly once the host screen or window is rotated or resized.
For example, if you have a UIView known as foo in the container UIView known as bar, and you need to pin foo’s leading and trailing edges to bar’s, in order bar develops and decreases flat, foo does too. Just before iOS 9, you could do this so using the following code:
That actually works, but it isn’t particularly pretty or readable, as well as for something so easy and broadly-used, UIKit was pleading for many convenience techniques. Starting with software development company , designers can use the brand new NSLayoutAnchor and UILayoutGuide classes to complete exactly the same factor with less and much more intuitive code:
But that’s only the beginning. While NSLayoutAnchor is really a easy factory class created for creating NSLayoutConstraint objects using convenience techniques, UILayoutGuide is really a more far-reaching, robust accessory for the woking platform.Previously, many common Auto Layout situations needed using dummy sights for instance, should you desired to use constraints to define how big empty space between two other sights, you’d to fill that space having a dummy view. Although this works (and using this method is prevalent), it’s generally considered bad practice, as you’re presenting lots of unnecessary overhead by instantiating a whole UIView object only to represent empty space. Furthermore, constraint-based designs can rapidly get untidy and hard to parse, particularly if you have numerous brother or sister sights in the bigger container.