框架: https://github.com/youngsoft/MyLinearLayout
pod 'MyLayout'
MyLinearLayout 布局
UILabel *lable = [UILabel new];
myTop /// 上边间距
myLeading /// 左边边距
myTrailing /// 右边边距
例如:
lable.myTop = 10;
lable.myLeading = 10;
lable.myLeading = 10;
/// 布局尺寸
myWidth
myHeight
mySize
例如:
lable.myWidth = 200;
lable.myHeight = 100;
lable.mySize = CGSizeMake(200, 100);
/// 自动计算高度
myHeight = MyLayoutSize.wrap;
例如:
lable.myHeight = MyLayoutSize.wrap;
/// 控件(水平)居中,(垂直)居中
myCenterX = 0; myCenterY = 0;
例如:
lable.myTop = 10;
lable.myCenterX = 0;
lable.mySize = CGSizeMake(200, 100);
待认证
rootLayout.widthSize.equalTo(scrollView.widthSize);
rootLayout.heightSize.equalTo(scrollView.heightSize).min(568 - 64);
待认证2 LLTest2ViewController
MyLinearLayout *contentLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
contentLayout.padding = UIEdgeInsetsMake(10, 10, 10, 10); //设置布局内的子视图离自己的边距.
contentLayout.myHorzMargin = 0; //同时指定左右边距为0表示宽度和父视图一样宽
contentLayout.heightSize.lBound(scrollView.heightSize, 10, 1); //高度虽然是自适应的。但是最小的高度不能低于父视图的高度加10.
[scrollView addSubview:contentLayout];
待优化 LLTest2ViewController
布局: MyOrientation_Horz 中
UIImageView *headImageView;
headImageView.myCenterY = 0; /// y轴垂直居中
MyLinearLayout *ageSelectLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
for (int i = 0; i < 3; i++) {
UILabel *ageLabel = [UILabel new];
ageLabel.weight = 1.0; //这里面每个子视图的宽度都是比重为1,最终的宽度是均分父视图的宽度
[ageSelectLayout addSubview:ageLabel];
}
动画刷新布局
MyLinearLayout *contentLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
[contentLayout layoutAnimationWithDuration:0.3];
布局 商品筛选
MyFrameLayout *frameLayout = [MyFrameLayout new];
frameLayout.backgroundColor = [UIColor redColor];
frameLayout.myHorzMargin = 0;
frameLayout.myVertMargin = 0;
frameLayout.topPos.equalTo(self.topLayoutGuide).offset(10); //顶部边距设置为10。
[self.view addSubview:frameLayout];
线性水平居中
MyLinearLayout *layout = [[MyLinearLayout alloc] initWithOrientation:MyOrientation_Horz];
layout.gravity = MyGravity_Horz_Center;
layout.backgroundColor = [UIColor grayColor];
layout.topPos.equalTo(self.topLayoutGuide).offset(10);
layout.myHorzMargin = 0;
layout.myHeight = MyLayoutSize.wrap;
[self.view addSubview:layout];
UIView *red = [UIView new];
red.backgroundColor = [UIColor redColor];
red.myWidth = 100;
red.myHeight = 50;
[layout addSubview:red];
UIView *blue = [UIView new];
blue.backgroundColor = [UIColor blueColor];
blue.myWidth = 100;
blue.myHeight = 50;
[layout addSubview:blue];
宽度写法等价
UILabel *v1 ;
v1.numberOfLines = 3;
v1.topPos.equalTo(self.topLayoutGuide).offset(10);
v1.myLeading = v1.myTrailing = 0; //宽度和父视图相等,等价v1.widthSize.equalTo(rootLayout.widthSize);
v2.widthSize.equalTo(rootLayout.widthSize).multiply(0.8); //子视图的宽度是父视图宽度的0.8
Label最大宽度
MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
UILabel *userInfoLabel;
userInfoLabel.widthSize.uBound(rootLayout.widthSize, 0, 2); //最大的宽度和父视图相等,这里第二个参数是第一个值的增量,第三个参数是第一个值的倍数
边距 -- 不能小于,不能超过
MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
UILabel *userDescLabel;
userDescLabel.leadingPos.equalTo(@0.05).min(17).max(19); /// 距离父视图左边为布局视图宽度的5%,但是最小不能小于17,最大不能超过19。
高度 -- 不能小于,不能超过
MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
UITextView *textView;
textView.heightSize.equalTo(@(MyLayoutSize.wrap)).max(300).min(60); /// //虽然高度自适应,但是仍然不能超过300的高度以及不能小于60的高度。
标签流
UIScrollView *scrollView = [UIScrollView new];
scrollView.backgroundColor = [UIColor whiteColor];
self.view = scrollView;
MyLinearLayout *rootLayout = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
rootLayout.myHorzMargin = 0;
rootLayout.gravity = MyGravity_Horz_Fill;
rootLayout.heightSize.lBound(scrollView.heightSize, 0, 1);
[scrollView addSubview:rootLayout];
MyFlowLayout *contentLayout = [MyFlowLayout flowLayoutWithOrientation:MyOrientation_Vert arrangedCount:0];
contentLayout.myHeight = MyLayoutSize.wrap;
contentLayout.padding = UIEdgeInsetsMake(5, 5, 5, 5);
contentLayout.subviewSpace = 5;
contentLayout.backgroundColor = [CFTool color:0];
[rootLayout addSubview:contentLayout];
contentLayout.autoArrange = YES; //自动排列,布局视图会根据里面子视图的尺寸进行智能的排列。
contentLayout.gravity = MyGravity_Horz_Fill; //对于内容填充流式布局来说会拉升所有子视图的尺寸,以便铺满整个布局视图。
//添加N个长短不一的子视图。
for (int i = 0; i < 15; i++)
{
UILabel *label = [UILabel new];
label.text = [NSString stringWithFormat:@"%02d",i];
label.adjustsFontSizeToFitWidth = YES;
label.textAlignment = NSTextAlignmentCenter;
label.myWidth = random() % 150 + 20; //最宽170,最小20.
label.myHeight = 30;
label.backgroundColor = [UIColor colorWithRed:random()%256 / 255.0 green:random()%256 / 255.0 blue:random()%256 / 255.0 alpha:1];
[contentLayout addSubview:label];
}
E998B177-521D-46AC-9997-3EC7AED597C8.png
流式布局,平均个数
MyFlowLayout *contentLayout = [MyFlowLayout flowLayoutWithOrientation:MyOrientation_Vert arrangedCount:3];
contentLayout.backgroundColor = [UIColor redColor];
contentLayout.myHorzMargin = 0;
contentLayout.myVertMargin = 0;
contentLayout.gravity = MyGravity_Horz_Fill | MyGravity_Vert_Fill;
contentLayout.padding = UIEdgeInsetsMake(0, 0, 0, 0);
contentLayout.subviewVSpace = 0; //设置流式布局里面子视图之间的垂直间距。
[vessel addSubview:contentLayout];
for (NSInteger i = 0; i < 3; i++) {
UIView *jj = [UIView new];
jj.backgroundColor = [UIColor jk_randomColor];
// jj.myVertMargin = 0;
// jj.myWidth = 20;
[contentLayout addSubview:jj];
}
BCBB7650-CFE7-4AB8-B438-90BD7086171E.png