美文网首页
OC UIView 链式设置约束优先级、基础属性

OC UIView 链式设置约束优先级、基础属性

作者: LiYaoPeng | 来源:发表于2018-10-10 18:33 被阅读0次
UIViewHandler.gif

代码点这里

链式编程对于实现一些基础设置,可能更简洁明了
比如实际的设置代码如下

  1. 顶部并排lable的基础设置:
  1. 其中设置优先级代码为
    .setUpUILayoutPriority(UILayoutPriorityRequired) .setUpUILayoutConstraintAxis(UILayoutConstraintAxisHorizontal)
  2. setUpUILayoutPriority:表示优先级越高,那么在父控件无法在无越界的情况下的情况下,就会优先先把优先级高的控件显示完整,然后再依次显示优先级低的
  3. 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;
}
  1. 底部重叠的按钮的基础设置:
[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);
            }];

相关文章

网友评论

      本文标题:OC UIView 链式设置约束优先级、基础属性

      本文链接:https://www.haomeiwen.com/subject/erdmaftx.html