TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | Apache 2 |
ReleasedLast Release | Aug 2015 |
Maintained by Dan Loewenherz.
This is a collection of helpful categories for use in iOS projects.
LHSCategoryCollection has a lot of great categories that are quick and easy to use. Here, I'm going to cover a few functions of the UIView+LHSAdditions category.
#import <LHSCategoryCollection/UIView+LHSAdditions.h>
@property (nonatomic, strong) UIView *redBox;
@property (nonatomic, strong) UIView *greenBox;
@property (nonatomic, strong) UIView *blueBox;
self.redBox = [[UIView alloc] init];
self.redBox.translatesAutoresizingMaskIntoConstraints = NO;
self.redBox.backgroundColor = [UIColor redColor];
self.greenBox = [[UIView alloc] init];
self.greenBox.translatesAutoresizingMaskIntoConstraints = NO;
self.greenBox.backgroundColor = [UIColor greenColor];
self.blueBox = [[UIView alloc] init];
self.blueBox.translatesAutoresizingMaskIntoConstraints = NO;
self.blueBox.backgroundColor = [UIColor blueColor];
[self.view addSubview:self.blueBox];
[self.blueBox lhs_expandToFillSuperviewWithVerticalMargin:20 horizontalMargin:20];
[self.blueBox addSubview:self.redBox];
[UIView lhs_addConstraints:@"H:[view(100)]" views:@[self.redBox]];
[UIView lhs_addConstraints:@"V:[view(100)]" views:@[self.redBox]];
[self.blueBox lhs_centerHorizontallyForView:self.redBox];
[self.blueBox lhs_centerVerticallyForView:self.redBox];
The end result looks like this:
NSDictionary *metrics = @{
@"verticalMargin": @(55),
@"horizontalMargin": @(15)
};
NSDictionary *views = @{
@"greenBox": self.greenBox,
@"redBox": self.redBox
};
[self.view addSubview:self.redBox];
[self.view addSubview:self.greenBox];
[UIView lhs_addConstraints:@"H:|-(horizontalMargin)-[view]-(horizontalMargin)-|" metrics:metrics views:@[self.redBox, self.greenBox]];
[self.redBox lhs_fillHeightOfSuperview];
[self.view lhs_addConstraints:@"V:|-(verticalMargin)-[greenBox]-(verticalMargin)-|" metrics:metrics views:views];
The end result looks like this:
You will not have any issues if you are building for iOS 7 or higher.
LHSCategoryCollection is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "LHSCategoryCollection"
Dan Loewenherz, [email protected]
LHSCategoryCollection is available under the Apache 2.0 license. See the LICENSE file for more info.