测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | Apache 2 |
发布最后发布 | 2015年8月 |
由 Dan Loewenherz 维护。
这是一个为 iOS 项目使用的有用分类的集合。
LHSCategoryCollection 拥有很多易于使用且功能强大的分类。以下,我将涵盖 UIView+LHSAdditions 类的几个功能。
#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];
最终结果如下
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];
最终结果如下
如果您为 iOS 7 或更高版本编译,则不会有任何问题。
LHSCategoryCollection 通过 CocoaPods 可用。要安装,只需将以下行添加到您的 Podfile 中
pod "LHSCategoryCollection"
Dan Loewenherz,[email protected]
LHSCategoryCollection 在 Apache 2.0 许可下可用。有关更多信息,请参阅 LICENSE 文件。