Latest 1.2.1
Homepage https://github.com/matteogobbi/UIView-MGConstraints
License MIT
Platforms ios 6.0, requires ARC
Frameworks UIKit
Authors

Category which allows to store, remove and replace easily constraints.

Info

This code must be used under ARC.
If your code doesn’t use ARC you can mark this source with the compiler flag -fobjc-arc

Example Usage

Let’s suppose to have a variable constraint, which should radically change (for instance when the user rotates the device). The default state would be this:

NSArray *viewConstraints =
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-exampleView-|" options:0 metrics:metrics views:views];

as we want to replace this constraint, but also keeping our code clean, first of all when we declare the constraint we use the following code to add it to the view, and store it:

static NSString * const kMGHorizontalViewConstraints = @"kMGHorizontalViewConstraints";

NSArray *viewConstraints =
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-exampleView-|" options:0 metrics:metrics views:views];

[view addAndStoreConstraints:viewConstraints forKey:kMGHorizontalViewConstraints];

Then, at the moment of the rotation:

NSArray *viewConstraints =
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-exampleView-10-newView-50-|" options:0 metrics:metrics views:views];

[view replaceConstraintsForKey:kMGHorizontalViewConstraints withConstraints:viewConstraints];

This is just an example of the usage. For further methods please check the (simple) header file.

Contact

Matteo Gobbi

License

UIView+MGConstraints is available under the MIT license.

Latest podspec

{
    "name": "UIView+MGConstraints",
    "version": "1.2.1",
    "summary": "Category which allows to store, remove and replace easily constraints.",
    "homepage": "https://github.com/matteogobbi/UIView-MGConstraints",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Matteo Gobbi": "[email protected]"
    },
    "source": {
        "git": "https://github.com/matteogobbi/UIView-MGConstraints.git",
        "tag": "1.2.1"
    },
    "platforms": {
        "ios": "6.0"
    },
    "source_files": "UIView+MGConstraints.{h,m}",
    "frameworks": "UIKit",
    "requires_arc": true
}

Pin It on Pinterest

Share This