///与下面约束对象属性截图相对应
//使用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. nginx自旋锁

    #include <stdio.h> #include <stdint.h> #include <unistd.h> /* typedef unsigned lon ...

  2. 【51NOD】1006 最长公共子序列Lcs(动态规划)

    给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的). 比如两个串为:   abcicba abdkscab   ab是两个串的子序列,abc也是,abca也是,其中abca是这两个 ...

  3. 使用ServiceDesk Plus保证及时解决问题,防止违反SLA

  4. ManageEngine的EventLog Analyzer许可信息

  5. Ajax的爬取心得

    一.查找到js的网址 在我们做爬虫的时候,如何判断一个数据是Ajax(asynchronous JavaScript And Xml,异步的JavaScript和Xml), 首先是数据的加载,在请求网 ...

  6. markdown中自己偶尔需要的小技巧

    慢慢积累,需要时搜索,并记录与此. 1.写文章时,由于markdown不负责首行缩进,所以“空格”需要特殊的方法去实现,最简单方便的是--输入全角空格(切换全角输入,点空格) 2.markdown中注 ...

  7. shell for if

    #!/bin/bash ..} do ];then j="${i}" else j="${i}" fi echo $j >> venn.log ec ...

  8. 2018.11.06 NOIP训练 简单的计数问题(计数dp)

    传送门 直接f[i][j]f[i][j]f[i][j]表示已经到第iii个位置已经找到jjj个的方案数. 简单转移一下就行了. 代码

  9. 2018.11.01 NOIP训练 图论(线段树+倍增+dfs序)

    传送门 一道挺妙的题. 对于询问点(u,v),如右图所示,我们可以发现存在一个点m在u->v的路径中,m子树的点到u是最近的,m子树外到v是最近的.其中dis(u,m)=(dis(u,v)-1) ...

  10. nigos core 安装配置

    系统环境      Apache        PHP        GCC compiler        GD development libraries 环境安装     yum install ...