MAConstraint 0.4

MAConstraint 0.4

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2015年1月

Derek 维护。



此项目使用 AutoLayout 非常方便。AutoLayout 的语法非常长,此项目将其缩短了很多。

使用方法

Objective-C

//Example 1
UIView *view = [[UIView alloc] init];
[view setBackgroundColor:[UIColor redColor]];
[self.view addSubview:view];
[view addMAConstraint:ConstraintCenterY | ConstraintCenterX | ConstraintFullHeight | ConstraintHalfWidth];

//Example 1
UIView *view = [[UIView alloc] init];
[view setBackgroundColor:[UIColor redColor]];
[self.view addSubview:view];
[view addLeftConstraint]; //Pin the view to the left of it's parent
[view addRightConstraint]; //Pin the view to the right of it's parent
[view addHeightConstraint:50.0]; //Set the view's height to 50
[view addCenterYConstraint]; //Center the view in it's parent

//Example 2
UIView *view = [[UIView alloc] init];
[view setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:view];
[view addConstraintsForFullSizedView]; //Make the view full size within it's parent

//Example 3
UIView *view = [[UIView alloc] init];
[view setBackgroundColor:[UIColor yellowColor]];
[self.view addSubview:view];
[view addRightConstraint];
[view addTopConstraint];
[view addBottomConstraint];
[self.view addConstraint:[Constraint on:view att:Left relatedBy:Equal to:self.view att:Left multiplier:1.0 const:30]]; //30 from the left

Swift

Swift 的语法几乎与 Objective-C 相同,但可以更短。

let someView = UIView()
someView.backgroundColor = UIColor.yellowColor()
view.addSubview(someView)
someView.addMAConstraint(.CenterX | .CenterY | .HalfWidth | .FullHeight)