upd

UpdateAutoLayoutConstraints

An easy way to create and update AutoLayout Constraints (Mainly to update Width and Height of UIView)

Showing:

Popularity

Downloads/wk

0

GitHub Stars

100

Maintenance

Last Commit

7yrs ago

Contributors

3

Package

Dependencies

0

License

MIT

Categories

Readme

UIView-UpdateAutoLayoutConstraints

An easy way to create and update AutoLayout Constraints (Mainly to update Width and Height of UIView)

alt text

1 - import Category

#import "UIView+UpdateAutoLayoutConstraints.h"

2 - create your UIViews

UIView *myView1 = [[UIView alloc]init];
one.backgroundColor = [UIColor redColor];
one.translatesAutoresizingMaskIntoConstraints = NO;  //<<-- Don't forget this line to enable AutoLayout
[self.view addSubview:one];

UIView *myView2 = [[UIView alloc]init];
two.backgroundColor = [UIColor blueColor];
two.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:two];

3 - create initial constraints

NSDictionary *metrics = @{@"height":@50.0};
NSDictionary *views = NSDictionaryOfVariableBindings(myView1,myView2);

[self.view addConstraints:[NSLayoutConstraint
                           constraintsWithVisualFormat:@"|-[one]-|"
                           options: 0
                           metrics:metrics
                           views:views]];

[self.view addConstraints:[NSLayoutConstraint
                                 constraintsWithVisualFormat:@"V:|-[myView1(50)][myView2]]"
                                 options:NSLayoutFormatAlignAllLeft | NSLayoutFormatAlignAllRight
                                 metrics:metrics
                                 views:views]];
                                     

4 - Whenever you want, Update this constraint

//Hide View
[myView1 setConstraintConstant:0 forAttribute:NSLayoutAttributeHeight];

//if constraint doesn't exist, it will be created
[myView1 setConstraintConstant:20 forAttribute:NSLayoutAttributeWidth];

//you can use tools to hide/show a uiview
[myView1 hideByHeight:YES];

//then
[myView1 hideByHeight:NO];

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100