本框架能同时布局多个view,只需将要布局的试图放到layout里,设置对齐方式以及间距即可完成布局。
期望写布局就像玩积木(Building Blocks)一样简单便捷有乐趣。所以,BBLayout又叫积木布局。
Using CocoaPods
-
Add the pod
BBLayout
to your Podfile.pod 'BBLayout'
-
运行pod install.
-
导入头文件
#import "BBLayoutView.h"
-
定义对象或者属性
BBLayoutView *layoutView = nil;
-
创建layoutView
CGRect rc = CGRectMake(0, naviBarHeight(), SCREEN_WIDTH, 50); _layoutView = [BBLayoutView layoutWithFrame:rc horizontalAlignment:BBLayoutHorizontalAlignmentCenter];
-
添加要布局的view
[_layoutView addView:v1 leading:10]; [_layoutView addView:v2] leading:20]; [_layoutView addView:v3] leading:30]; [_layoutView addView:v4] leading:5];
-
加到父view上
[self.view addSubview:_layoutView];
优势:
- 布局依赖低,view之间不会明确依赖关系
- 支持多行模式布局
- 支持6种水平布局和5种垂直对齐方式