LHSCategoryCollection 0.0.22

LHSCategoryCollection 0.0.22

测试已测试
Lang语言 Obj-CObjective C
许可证 Apache 2
发布最后发布2015年8月

Dan Loewenherz 维护。



  • Dan Loewenherz

这是一个为 iOS 项目使用的有用分类的集合。

使用方法

LHSCategoryCollection 拥有很多易于使用且功能强大的分类。以下,我将涵盖 UIView+LHSAdditions 类的几个功能。

使用 LHSCategoryCollection 的 UIView+LHSAdditions 所需的导入和协议

#import <LHSCategoryCollection/UIView+LHSAdditions.h>

对于这些示例,我们将使用三个视图

@property (nonatomic, strong) UIView *redBox;
@property (nonatomic, strong) UIView *greenBox;
@property (nonatomic, strong) UIView *blueBox;

在 viewDidLoad 方法中初始化您的视图

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];

最终结果如下

image

使用边距定位视图

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];

最终结果如下

image

需求

如果您为 iOS 7 或更高版本编译,则不会有任何问题。

安装

LHSCategoryCollection 通过 CocoaPods 可用。要安装,只需将以下行添加到您的 Podfile 中

pod "LHSCategoryCollection"

作者

Dan Loewenherz,[email protected]

许可证

LHSCategoryCollection 在 Apache 2.0 许可下可用。有关更多信息,请参阅 LICENSE 文件。