創(chuàng)建 view 使用 PureLayout 布局,詳細(xì)用法
// 距離父視圖左邊距20
[purpleView autoPinEdgeToSuperviewEdge:(ALEdgeLeft) withInset:20.0];
// 距離父視圖上邊距100
[purpleView autoPinEdgeToSuperviewEdge:(ALEdgeTop) withInset:100.0];
// 設(shè)置 view 的 size
[purpleView autoSetDimensionsToSize:CGSizeMake(100, 100)];
// 左邊距離 purpleView 右邊距30
[orangeView autoPinEdge:(ALEdgeLeft) toEdge:(ALEdgeRight) ofView:purpleView withOffset:30];
// purpleView 和 orangeView 登高等寬
[@[orangeView,purpleView] autoMatchViewsDimension:(ALDimensionWidth)];
[@[orangeView,purpleView] autoMatchViewsDimension:(ALDimensionHeight)];
// orangeView 與 purpleView 水平對(duì)齊
[orangeView autoAlignAxis:(ALAxisHorizontal) toSameAxisOfView:purpleView];
// 距離父視圖底部50 (這里是距離,不是坐標(biāo))
[magentaView autoPinEdgeToSuperviewEdge:(ALEdgeBottom) withInset:50];
// magentaView 與 purpleView 左對(duì)齊
[magentaView autoPinEdge:(ALEdgeLeft) toEdge:(ALEdgeLeft) ofView:purpleView];
// 設(shè)置 magentaView 的寬度
[magentaView autoSetDimension:(ALDimensionWidth) toSize:150];
// 設(shè)置 magentaView 的高度
[magentaView autoSetDimension:(ALDimensionHeight) toSize:150];
// 設(shè)置 yellowView 距 magentaView 的內(nèi)邊距全部是20
ALEdgeInsets defInsets = ALEdgeInsetsMake(20.0,20.0,20.0,20.0);
[yellowView autoPinEdgesToSuperviewEdgesWithInsets:defInsets];
運(yùn)行結(jié)果如圖:
// purpleView 在父視圖中心
[purpleView autoCenterInSuperview];
// purpleView 的寬高均為 100
[purpleView autoSetDimensionsToSize:CGSizeMake(100, 100)];
// orangeView 與 purpleView 的左邊對(duì)齊
[orangeView autoPinEdge:(ALEdgeLeft) toEdge:(ALEdgeLeft) ofView:purpleView];
// orangeView 的頂部距離 purpleView 底部 10
[orangeView autoPinEdge:(ALEdgeTop) toEdge:(ALEdgeBottom) ofView:purpleView withOffset:10];
// orangeView 右邊距父視圖 20
[orangeView autoPinEdgeToSuperviewEdge:(ALEdgeRight) withInset:20];
// oragenView 的高度為 purpleView 的一半
[orangeView autoMatchDimension:(ALDimensionHeight) toDimension:(ALDimensionHeight) ofView:purpleView withMultiplier:0.5];
// purpleView在父視圖上水平居中
[purpleView autoAlignAxisToSuperviewAxis:(ALAxisHorizontal)];
NSArray * views = @[purpleView, orangeView, magentaView, yellowView];
// 四個(gè) view 的高均為40
[views autoSetViewsDimension:(ALDimensionHeight) toSize:40];
// 水平方向上,四個(gè)viwe間距為10,依次排序
[views autoDistributeViewsAlongAxis:(ALAxisHorizontal) alignedTo:(ALAttributeHorizontal) withFixedSpacing:10.0 insetSpacing:YES matchedSizes:YES];