///与下面约束对象属性截图相对应
//使用Auto Layout约束,禁止将Autoresizing Mask转换为约束
[self.funcView setTranslatesAutoresizingMaskIntoConstraints:NO];
/**
*@1.constraintWithItem:你想要约束的视图
*@2.attribute:约束的属性(枚举值,可使用com键查看)
*@3.relatedBy:与约束的父视图的关系(枚举值)
*@4.toItem:约束对象的父视图
*@5.attribute:约束的属性(枚举值,可使用com键查看),一般情况下与第二个参数写一样的
*@6.multiplier:相对于父视图的约束比例
*@7.constant:约束间隔
*/
//与约束视图与父视图宽度一致
NSLayoutConstraint *w = [NSLayoutConstraint constraintWithItem:_funcView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:_fview attribute:NSLayoutAttributeWidth multiplier:1 constant:0];
//与约束视图与父视图高度一致
NSLayoutConstraint *h = [NSLayoutConstraint constraintWithItem:_funcView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:_fview attribute:NSLayoutAttributeHeight multiplier:1 constant:0];
//与约束视图与父视图center.x一致
NSLayoutConstraint *x = [NSLayoutConstraint constraintWithItem:_funcView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_fview attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
//与约束视图与父视图center.y一致
NSLayoutConstraint *y = [NSLayoutConstraint constraintWithItem:_funcView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_fview attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; //把约束添加到父视图上
NSArray *array = @[w,h,x,y];
[_fview addConstraints:array];

 

iOS 使用代码创建约束,实现自动布局的更多相关文章

  1. ios - 纯代码创建collectionView

    开始考虑好一点点时间,因为一般的都是用xib,或者storyboard来写的.这次用纯代码...废话较多请看 首先把storyboard干掉,工程里面的main干掉 由于干掉了storyboard则启 ...

  2. IOS AutoLayout 代码实现约束—VFL

    在autolayout下,尽管使用IB来拖放控件,但仍然避免不了用代码来创建控件,这是约束需要代码来实现. IOS 提供了两种添加约束的方法 第一种: +(instancetype)constrain ...

  3. SQL Server 数据表代码创建约束

    约束 非空约束 --NN,ont null constraint 必须填写数据不能为空 --指定表 Student 添加名为NN_Student_sClassId非空约束(指定列名sClassId), ...

  4. ios navigationController代码创建

    1.新建类文件FirstViewController,subClass of:UIViewController 2.新建类文件MYNavigationController,subClass of:UI ...

  5. 使用代码创建AutoLayout约束

    使用代码创建AutoLayout约束 1.代码创建约束的步骤 2.代码创建约束的常用方法 3.代码创建约束的原则 4.禁用Autoresizing的原因 5. 设置相对状态栏的约束,使用self.to ...

  6. Sql Server——运用代码创建数据库及约束

    在没有学习运用代码创建数据库.表和约束之前,我们只能用鼠标点击操作,这样看起来就不那么直观(高大上)了. 在写代码前要知道在哪里写和怎么运行: 点击新建查询,然后中间的白色空白地方就是写代码的地方了. ...

  7. 【转】iOS6中的Auto Layout:通过代码添加约束

        最近做的项目用到了Auto Layout,于是经过了一番大量的google,这是我看到的讲用代码创建约束最清晰的一篇教程,于是想跟更多的人分享一下.原文也比较简单,可以直接过去看,如果我翻译的 ...

  8. SqlServer--代码创建约束

    约束-保证数据完整性先用设计器创建约束,再用代码创建约束.数据库约束是为了保证数据的完整性(正确性)而实现的一套机制非空约束 (选择复选框)not null主键约束(PK)primary key co ...

  9. 【转】iOS学习之Autolayout(代码添加约束) -- 不错不错

    原文网址:http://www.cnblogs.com/HypeCheng/articles/4192154.html DECEMBER 07, 2013 学习资料 文章 Beginning Auto ...

随机推荐

  1. Porsche PIWIS III with V37.250.020 Piwis 3 Software Update New Feature

    Porsche Piwis tester 3 PT3G VCI with V37.250.020 Piwis 3 Software unlimited license installed on Ful ...

  2. FPKM与RPKM

    FPKM与RPKM (2015-01-09 23:55:17) 转载▼ 标签: 转载   原文地址:FPKM与RPKM作者:Fiona_72965 定义:  FPKM:Fragment Per Kil ...

  3. jquery Nestable 获取改变排序后的json数据 拖动排序

    <script type="text/javascript"> jQuery(function($){ $('.dd').nestable(); $('.dd-hand ...

  4. win8 本地化

    先看个简单的案例:新时尚Windows8开发(6):资源 & 本地化 http://www.silverlightchina.net/html/windows8/study/2012/0902 ...

  5. centos7 hive + 远程mysql 搭建笔记

    1.require:java环境,本地可用的hadoop,远程可访问的mysql 2.拷贝hive文件(hive-2.2.1) 3.设置环境变量 export HIVE_HOME=/data/spar ...

  6. 基础知识之nginx重写规则

    nginx重写规则 nginx rewrite 正则表达式匹配 大小写匹配 ~ 为区分大小写匹配 ~* 为不区分大小写匹配 !~和!~*分别为区分大小写不匹配及不区分大小写不匹配 文件及目录匹配 -f ...

  7. 2018.11.30 spoj220 Relevant Phrases of Annihilation(后缀数组+二分答案)

    传送门 代码: 先用特殊字符把所有字符串连接在一起. 然后二分答案将sasasa数组分组. 讨论是否存在一个组满足组内对于每一个字符串都存在两段不相交字串满足条件. #include<bits/ ...

  8. (1)There's more to life than being happy

    https://www.ted.com/talks/emily_esfahani_smith_there_s_more_to_life_than_being_happy00:12 I used to ...

  9. 交换机的Access口与Trunk口

    基本概念 Access类型的端口只能属于1个VLAN,一般用于连接计算机的端口:Trunk类型的端口可以允许多个VLAN通过,可以接收和发送多个VLAN的报文,一般用于交换机之间连接的端口: 处理流程 ...

  10. 师弟推荐软件-/mathpix

    将公式扫描为latex:https://mathpix.com/api.html mathtype与latex转换:http://www.mathtype.cn/jiqiao/zhuanhua-gon ...