![](https://img.haomeiwen.com/i4185621/4fec9deae248602d.gif)
链式编程对于实现一些基础设置,可能更简洁明了
比如实际的设置代码如下
- 顶部并排lable的基础设置:
- 其中设置优先级代码为
.setUpUILayoutPriority(UILayoutPriorityRequired) .setUpUILayoutConstraintAxis(UILayoutConstraintAxisHorizontal)
setUpUILayoutPriority:
表示优先级越高,那么在父控件无法在无越界的情况下的情况下,就会优先先把优先级高的控件显示完整,然后再依次显示优先级低的setUpUILayoutConstraintAxis:
优先级 轴线
横向还是纵向进行优先级限制
/// - leftLabel label
- (UILabel *) leftLabel {
if (!_leftLabel) {
_leftLabel = [UILabel new];
_leftLabel.textAlignment = NSTextAlignmentLeft;
_leftLabel
.setUpText(@"第一个")
.setUpTextColorRGBA(23,22,39,0.6)
.setUpAlignment(NSTextAlignmentLeft)
.setUpUILayoutPriority(UILayoutPriorityRequired)
.setUpUILayoutConstraintAxis(UILayoutConstraintAxisHorizontal)
.setUpBorderColor(UIColor.redColor)
.setUpBorderWidth(1)
.setUpCornerRadius(4)
.setUpMasksToBounds(true);
}
return _leftLabel;
}
- 底部重叠的按钮的基础设置:
[button setUpStyle:UIControlStateNormal style:^(UIButton *button) {
button
.setUpImage([UIImage imageNamed:@"".addInt(index)])
.setUpBackgroundColor(UIColor.whiteColor)
.setUpTitleColor(UIColor.whiteColor)
.setUpBorderWidth(2)
.setUpBorderColor(UIColor.whiteColor)
.setUpFont([UIFont systemFontOfSize:24])
.setUpMasksToBounds(true)
.setUpCornerRadius(button.frame.size.width/2.0);
}];
网友评论