第30月第18天 autolayout代码
1.上下左右
[tipsLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; {
id view1 = tipsLabel;
id view2 = self;
//子view的上边缘离父view的上边缘 NSLayoutConstraint *contraint1 = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]; //子view的左边缘离父view的左边缘 NSLayoutConstraint *contraint2 = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0]; //子view的下边缘离父view的下边缘 NSLayoutConstraint *contraint3 = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-btnHeight]; //子view的右边缘离父view的右边缘 NSLayoutConstraint *contraint4 = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0]; //把约束添加到父视图上 NSArray *array = [NSArray arrayWithObjects:contraint1, contraint2, contraint3, contraint4, nil,nil]; [self addConstraints:array];
}
宽高
[imgv setTranslatesAutoresizingMaskIntoConstraints:NO]; {
id view1 = imgv;
id view2 = self.view;
id viewNil = nil;
// NSLayoutConstraint *contraint1 = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:viewNil attribute:NSLayoutAttributeWidth multiplier:1.0 constant:size.width];
[imgv addConstraint:contraint1];
// NSLayoutConstraint *contraint2 = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:viewNil attribute:NSLayoutAttributeHeight multiplier:1.0 constant:size.height];
[imgv addConstraint:contraint2];
//子view的下边缘离父view的下边缘 NSLayoutConstraint *contraint3 = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0]; //子view的右边缘离父view的右边缘 NSLayoutConstraint *contraint4 = [NSLayoutConstraint constraintWithItem:view1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:view2 attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0]; //把约束添加到父视图上 NSArray *array = [NSArray arrayWithObjects:contraint3, contraint4, nil,nil]; [self.view addConstraints:array]; }
https://www.jianshu.com/p/3c2f41e2ef6e
第30月第18天 autolayout代码的更多相关文章
- 30个php操作redis常用方法代码例子
From: http://www.jb51.net/article/51884.htm 这篇文章主要介绍了30个php操作redis常用方法代码例子,本文其实不止30个方法,可以操作string类型. ...
- 30 个 php 操作 redis 常用方法代码例子
这篇文章主要介绍了 30 个 php 操作 redis 常用方法代码例子 , 本文其实不止 30 个方法 , 可以操作 string 类型. list 类型和 set 类型的数据 , 需要的朋友可以参 ...
- 爱漂泊人生 30个php操作redis常用方法代码例子
http://www.justwinit.cn/post/8789/ 背景:redis这个新产品在sns时很火,而memcache早就存在, 但redis提供出来的功能,好多网站均把它当memcach ...
- 30个php操作redis常用方法代码例子【转】
背景:redis这个新产品在sns时很火,而memcache早就存在, 但redis提供出来的功能,好多网站均把它当memcache使用,这是大才小用,这儿有30个方法来使用redis,值得了解. 这 ...
- 18 行 JS 代码编一个倒时器
有时候在生活中,你需要一个JavaScript倒计时时钟,而不是一个末日装置设备.不管你是否有一次约会,销售.促销.或者游戏,你可以受益于使用原生JavaScript构建一个时钟,而不是拿到一个现成的 ...
- NVIDIA-docker报错:docker-ce (= 5:18.09.0~3-0~ubuntu-xenial) but 18.06.0~ce~3-0~ubuntu is to be installed
报错: The following packages have unmet dependencies: nvidia-docker2 : Depends: docker-ce (= 5:18.09.0 ...
- Apache2.4.23+PHP5.6.30+MySQL5.7.18安装教程
最近在工作中常常接触到PHP,自己也写过一些简单的PHP页面.我们知道PHP是在服务器端运行的脚本语言,因此我们需要配置服务器环境.之前为了省事直接使用的是wamp集成环境,但是突然某一天领导要求我们 ...
- IOS AutoLayout 代码实现约束—VFL
在autolayout下,尽管使用IB来拖放控件,但仍然避免不了用代码来创建控件,这是约束需要代码来实现. IOS 提供了两种添加约束的方法 第一种: +(instancetype)constrain ...
- 【转】iOS学习之Autolayout(代码添加约束) -- 不错不错
原文网址:http://www.cnblogs.com/HypeCheng/articles/4192154.html DECEMBER 07, 2013 学习资料 文章 Beginning Auto ...
随机推荐
- 如何在element-UI 组件的change事件中传递自定义参数
以select为例,如果select写在循环里,触发change事件时可能不只需要传递被选中项的值,还要传递index过去,来改变同一循环中的其他标签的状态. 下面这样写是无效的: @change=& ...
- php之微信公众号发送模板消息
讲一下开发项目中微信公众号发送模板消息的实现过程(我用的还是Thinkphp5.0). 先看一下效果,如图: 就是类似于这样的,下面讲一下实现过程: 第一步:微信公众号申请模板消息权限: 立即申请: ...
- 03-MySQL表操作
MySQL表操作 1.介绍 表就相当于文件,表中的一条记录就相当与文件的一行内容,不同的是,表中的一条记录有对应的标题,成为表的字段. 2.创建表 2.1语法 create table 表名( 字段名 ...
- git添加秘钥提示Key is already in use
种种原因,需要修改git账号的秘钥. 操作如下: 1.删除系统上.ssh下的known_hosts文件 (一般在这个路径下C:\Users\Administrator\.ssh)如果账号不是Admi ...
- MediaManager配置公网访问功能
安装时设置传输本地地址及端口,如图: 路由器设置端口映射,如下图 使用时,打开公网地址http://IpAddress:8090/ContentManager/MainPage.aspx?zh-CN# ...
- js 前端常用排序算法总结
(冒泡排序.快排顺序.选择排序.插入排序.归并排序) 下面是前端比较常用的五个算法demo: 冒泡算法:比较两个相邻的数值,if第一个>第二个,交换他们的位置元素项向上移动至正确的顺序. fun ...
- [转帖]为应用程序池“XXX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误。该进程 ID 为“XXXX”。数据字段包含错误号。
[终极解决方案]为应用程序池“XXX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误.该进程 ID 为“XXXX”.数据字段包含错误号. ...
- 基于Python玩转人工智能最火框架 TensorFlow应用实践
慕K网-299元-基于Python玩转人工智能最火框架 TensorFlow应用实践 需要联系我,QQ:1844912514
- 低版本Flume兼容高版本elasticsearch
Flume更新比较慢,而elasticsearch更新非常快所以当涉及更换elasticsearch版本时会出现不兼容问题. apache-flume-1.6.0+elasticsearch1.5.1 ...
- java回调函数,看完就懂
java回调函数在网上了看了些例子,比较绕,不够清晰,自己写的一个例子比较通俗,java回调其实很简单. 举个例子我是类B,我有个方法叫b(),现在我要调用类A中的方法a(),写个代码就是: publ ...