• 自动布局的不同实现方式


    autoLayout自动布局

    三种方式添加约束:

    1. 界面操作;

    2. 手写代码;

    3. 视觉化格式语言;

    方式1

    在属性框中输入相应的属性值即可(注意属性的冲突设置与属性缺失)

    方式2:

    //求算公式: redView.height = self.view.top*0.2 + 20

        //给redView添加顶部间距约束,相对于self.view的顶部,设为20个像素

        NSLayoutConstraint *redViewTop = [NSLayoutConstraint constraintWithItem:redView

                                                                      attribute:NSLayoutAttributeTop

                                                                      relatedBy:NSLayoutRelationEqual

                                                                         toItem:self.view

                                                                      attribute:NSLayoutAttributeTop

                                                                     multiplier:1

                                                                       constant:20];

        [self.view addConstraint:redViewTop];

    方式3:

    NSDictionary *dic = @{@"mainView":self.view,@"topView":redView,@"bottomView":blueView};

        NSArray *arrBlueV = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[topView]-20-[bottomView(==100)]" options:0 metrics:nil views:dic];

        NSArray *arrBlueH = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[topView]-20-[bottomView(==50)]" options:0 metrics:nil views:dic];

        [self.view addConstraints:arrBlueV];

        [self.view addConstraints:arrBlueH];

    http://www.cnblogs.com/PaulpauL/ 版权声明:本文为博主原创文章,未经博主允许不得转载。
  • 相关阅读:
    内容可编辑且随内容自增长的div
    05-图1. List Components (25)
    多button事件处理
    NYOJ 496 [巡回赛-拓扑排序]
    Android lollipop 更新问题
    编程算法
    Codeforces Round #337 (Div. 2) 610B Vika and Squares(脑洞)
    java中的ShortBuffer
    Rust hello world 语法解说
    在.Net MVC结构API接口中推断http头信息实现公共的权限验证过滤器演示样例
  • 原文地址:https://www.cnblogs.com/PaulpauL/p/4935233.html
Copyright © 2020-2023  润新知