2019独角兽企业重金招聘Python工程师标准>>>

//

//  ViewController.m

//  02-手写约束

//

//  Created by 鹿微微鹿 on 16/5/5.

//  Copyright (c) 2016年 鹿微微鹿. All rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

//手动添加约束

//1.必须先将需要添加约束的视图创建出来

//并且添加到界面上

//2.不需要设置frame

//关闭autoresizing

//1.创建一个红色视图

UIView *redView = [[UIView alloc]init];

redView.backgroundColor = [UIColor redColor];

//关闭autoresizing

redView.translatesAutoresizingMaskIntoConstraints = NO;

//创建一个绿色视图

UIView *greenView = [[UIView alloc]init];

greenView.backgroundColor = [UIColor greenColor];

greenView.translatesAutoresizingMaskIntoConstraints = NO;

//显示在界面上

[self.view addSubview:redView];

[self.view addSubview:greenView];

//2.添加约束(红色视图一值显示在左上角

//到屏幕顶部和左边的距离为50,宽高200)

//top

//红色视图的顶部 = view顶部*1 + 50

//redView.top = self.view.top*1 + 50;

//参数1的参数2参数3参数4的参数5 * 参数6 + 参数7

NSLayoutConstraint *redtopConstraint = [NSLayoutConstraint

constraintWithItem:redView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:50];

//left

NSLayoutConstraint *redLeftConstraint = [NSLayoutConstraint

constraintWithItem:redView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:50];

//width

NSLayoutConstraint *redWith = [NSLayoutConstraint

constraintWithItem:redView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:0 constant:200];

//height

NSLayoutConstraint *redHeight = [NSLayoutConstraint

constraintWithItem:redView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:0 constant:200];

//b.添加约束

[self.view addConstraints:@[ redtopConstraint,redLeftConstraint]];

[redView addConstraints:@[ redWith,redHeight]];

//=============绿色视图的约束==============

//左对齐

NSLayoutConstraint *greenAlignLeft = [NSLayoutConstraint

constraintWithItem:greenView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:redView attribute:NSLayoutAttributeLeading multiplier:1 constant:0];

//到红色视图底部的距离

NSLayoutConstraint *greenTop = [NSLayoutConstraint

constraintWithItem:greenView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:redView attribute:NSLayoutAttributeBottom multiplier:1 constant:50];

//宽度

NSLayoutConstraint *greenWidth = [NSLayoutConstraint

constraintWithItem:greenView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:redView attribute:NSLayoutAttributeWidth multiplier:0.5 constant:0];

//高度

NSLayoutConstraint *greenHeight = [NSLayoutConstraint

constraintWithItem:greenView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:redView attribute:NSLayoutAttributeHeight multiplier:0.5 constant:0];

[self.view addConstraints:@[greenHeight,greenWidth,greenAlignLeft,greenTop]];

}

@end

转载于:https://my.oschina.net/luhoney/blog/670660

IOS开发之手写约束相关推荐

  1. AI应用开发实战 - 手写识别应用入门

    AI应用开发实战 - 手写识别应用入门 手写体识别的应用已经非常流行了,如输入法,图片中的文字识别等.但对于大多数开发人员来说,如何实现这样的一个应用,还是会感觉无从下手.本文从简单的MNIST训练出 ...

  2. python基于轻量级CNN模型开发构建手写藏文数字识别系统

    最近做的很多工作都是跟手写性质的数据集有关的,比如:手写汉字.手写甲骨文.手写数字.手写字母等等,今天主要做的实践是对藏文中的手写数字进行识别分析,在我之前的博文中有很多相关的实践分析,感兴趣的话可以 ...

  3. Winform开发中手写签名的实现

    由于项目的需要,需要在项目的Winform系统的一个模块中集成手写签名的功能,一开始对这块不是很了解,只是了解他能够替代鼠标进行签名.既然是签名,一般就是需要记录手稿图片,作为一个记录核实的凭证,因为 ...

  4. autosar工具链_Autosar开发与手写代码开发的区别

    Autosar开发流程 1.BSW开发 主要应用工具链(Vector等工具,具体可以百度搜索Autosar配置工具)来配置,复杂驱动的代码需要手写,但是也要符合Autosar的接口标准,主要包括,CA ...

  5. 大疆无人机开发:手写全景(思路 + 大疆的坑)

    大疆手写全景的三个思路: 1.采用missionTimeLine的方式实现. 2.采用航点的方式WayPoint实现. 3.采用虚拟摇杆的方式VirtualStick实现. 第一种方案: 其中最符合软 ...

  6. 2016:iOS开发趋势思考--写的有趣~

    参加GMTC大会,第一个议题就是<移动开发的未来展望>,有些启发整理记录一下. 编程神作<代码大全>提过,在技术浪潮中找到自己的位置.编程技术的更迭越来越快,当进行技术选择时, ...

  7. AI应用开发实战 - 手写算式计算器

    扩展手写数字识别应用 识别并计算简单手写数学表达式 主要知识点 了解MNIST数据集 了解如何扩展数据集 实现手写算式计算器 简介 本文将介绍一例支持识别手写数学表达式并对其进行计算的人工智能应用的开 ...

  8. iOS开发,这样写简历才能获得大厂青睐

    前言: 对于职场来说,简历就如同门面.若是没想好,出了差错,耽误些时日倒不打紧,便是这简历入不了HR的眼,费力伤神还不能觅得好去处,这数年来勤学苦练的大好光阴,岂不辜负? 简历,简而有力.是对一个人工 ...

  9. iOS开发简历这样写,面试电话接到手软

    序言 <围城>里将婚姻形容为一个围城,城内的想出去,城外的想进去,其实职场又何尝不是另一个围城,因此跳槽.卧槽的纷争不断在身边上演.俗话说"金三银四",这正是每年各家企 ...

最新文章

  1. 上海电力大学计算机专业分数线,上海电力大学2020年录取分数线(附2017-2020年分数线)...
  2. 《柳叶刀》:群体免疫不靠谱!欧洲迄今最大新冠血清学调查显示,西班牙抗体阳性率仅5%...
  3. 单实例模式(singleton)
  4. 如何更改 Linux/Unix 登录账号的密码
  5. INLINE HOOK过驱动保护的理论知识和大概思路
  6. java避免内存泄露_Java防止非静态内部类内存泄漏
  7. 动态规划(冬令营课堂笔记)
  8. Spring集成–第1节– Hello World
  9. [动画工具] Animations
  10. C++中公有继承、保护继承、私有继承
  11. iOS 程序上传流程
  12. 南阳理工ACM 题目33 蛇形填数
  13. 控制pico—unity中双目摄像机的clearFlags问题
  14. python计算定积分_python 求定积分和不定积分示例
  15. python中的MRO
  16. 不知道音频格式转换软件哪个好?打工人都在用的几款你别错过
  17. kali linux 中的网卡驱动,kali linux 安装Realtek 8812AU网卡驱动
  18. Flash 视频蓬勃发展
  19. 淘宝/天猫API:item_videolist_cat-获取淘宝直播分类id接口
  20. 开发者测评:阿里云 ACR 与其他的镜像仓库到底有什么不同?

热门文章

  1. python免费试听-哈尔滨Python人工智能课程免费试听
  2. 以下可以采用python语言保留字的是-以下选项中不是 Python 语言的保留字的是
  3. 6翻了C语言,《嗨翻C语言》随书练习六 6章 二叉树简单例子
  4. 微信公众平台开发 OAuth2.0网页授权认证
  5. LeetCode Design Twitter
  6. nginx的启动初始化过程(一)
  7. 什么是.Net, IL, CLI, BCL, FCL, CTS, CLS, CLR, JIT
  8. .Net 3.5新特性(1)Automatic Properties, Object Initializers, and Collection Initializers
  9. 【luogu P2919 [USACO08NOV]守护农场Guarding the Farm】 题解
  10. linux ----- Vim进入和退出命令