UIView *topView = [[UIView alloc] init];
topView.backgroundColor = [UIColor redColor];
[self.view addSubview:topView];
topView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addConstraints:@[ [NSLayoutConstraint constraintWithItem:topView
attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:],
[NSLayoutConstraint constraintWithItem:topView
attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-],
[NSLayoutConstraint constraintWithItem:topView
attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:],
[NSLayoutConstraint constraintWithItem:topView
attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:]
]];

topView在父视图的左边间距10,下边间距-10,宽度为100,高度为20的实现代码

NSLayoutConstraint的简单应用的更多相关文章

  1. NSLayoutConstraint 布局,配合简单的动画效果

    demo地址 :链接: http://pan.baidu.com/s/1c00ipDQ 密码: mi4c 1 @interface ViewController () @property (nonat ...

  2. Swift技术之如何在iOS 8下使用Swift设计一个自定义的输入法 (主要是NSLayoutConstraint 的使用)

    当前位置: > Swift新手入门 > Swift技术之如何在iOS 8下使用Swift设计一个自定义的输入法 时间:2014-09-10 16:49来源:未知 作者:啊成 举报 点击:5 ...

  3. AutoLayout的三种设置方式之——NSLayoutConstraint代码篇

    AutoLayout是从IOS 6开始苹果引入来取代autoresizing的新的布局技术,该技术有三种设置方式,等下我来为大家一一叙述一下. 在说三种设置方式前,我们先简单的说一下autolayou ...

  4. iOS开发——适配篇&App适配简单概括

    App适配简单概括 1:适配:适应.兼容各种不同的情况 系统适配 针对不同版本的操作系统进行适配 屏幕适配 针对不同大小的屏幕尺寸进行适配 在用户眼中 屏幕是由无数个像素组成的 像素越多,屏幕越清晰 ...

  5. iOS开发通过代码方式使用AutoLayout (NSLayoutConstraint + Masonry)

    iOS开发通过代码方式使用AutoLayout (NSLayoutConstraint + Masonry) 随着iPhone6/6+设备的上市,如何让手头上的APP适配多种机型多种屏幕尺寸变得尤为迫 ...

  6. Objectiv-C UIKit基础 NSLayoutConstraint的使用(VFL实现)

    利用VFL可视化语言 (简单的抛砖引玉) 构建3个View 橙色和绿色左中右间隔20 上间隔40 高为200 蓝色在橙色内(0,0)处 宽高为橙色的一半 实现效果如下 由于atutosize和auto ...

  7. iOS原生自动布局NSLayoutConstraint

    AutoLayout概念是苹果自iOS6开始引入的概念. 目前为止,实现自动布局技术选型方面也可以使用xib和storyboard.在开发过程中通常登录.注册等变动可能性较小的视图,我会采用xib开发 ...

  8. 第三方框架-纯代码布局:Masonry的简单使用

    Masonry是一个对系统NSLayoutConstraint进行封装的第三方自动布局框架,采用链式编程的方式提供给开发者API.系统AutoLayout支持的操作,Masonry都支持,相比系统AP ...

  9. Auto Layout简单应用——以编码的方式实现Auto Layout自动布局(二)

    在上一篇文章iOS学习笔记02——以编码的方式实现Auto Layout自动布局(一)中我们简单的介绍了使用Visual Format Language创建布局约束来实现自动布局,这种方法创建的布局约 ...

随机推荐

  1. android操作sqlite数据库及心得

    写这篇文章主要是网上的对sqlite的操作太多且太杂,非常多时候都不能非常好的运用到自己的项目中,结构不清晰,我自己写了一篇适合刚刚接触的人看的操作方法. 近来用android时要将一些数据保存起来, ...

  2. 线程中sleep方法和wait方法有什么区别?(转)

    本文转自https://www.cnblogs.com/linkstar/p/6043846.html 线程中sleep方法和wait方法有什么区别?   如果你没有接触过java的多线程,那么多对于 ...

  3. ASP.NET MVC:Form Authentication 相关的学习资源

    看完此图就懂了 看完下面文章必须精通 Form authentication and authorization in ASP.NET Explained: Forms Authentication ...

  4. [转]PHP: 深入pack/unpack

    From : http://my.oschina.net/goal/blog/195749 http://www.w3school.com.cn/php/func_misc_pack.asp PHP作 ...

  5. Netty Associated -- ChannelPipeline

    A list of ChannelHandlers which handles or intercepts inbound events and outbound operations of a Ch ...

  6. IDEA 快速将spring boot项目打包成jar包,简单快速有效

    原文地址;https://blog.csdn.net/chen846262292/article/details/80701101  https://www.cnblogs.com/chrischen ...

  7. 第三章 消息摘要算法--MD5

    注意:本节内容主要参考自<Java加密与解密的艺术(第2版)>第6章“验证数据完整性--消息摘要算法” 3.1.消息摘要算法:防止消息在传递过程中被篡改. 原理:任何消息经过消息摘要算法后 ...

  8. Fedora 18/19没有注销

    sudo yum install dconf-editor -y 定位到org > gnome > shell  勾选always-show-log-out http://www.ryan ...

  9. SGU536 Berland Chess

    棋盘上白子只有一个国王  黑子给出 各子遵从国际象棋的走法 黑子不动,白子不能走进黑子的攻击范围以内 问白字能不能吃掉所有的黑子 直接搜索就好了,各子状态用二进制表示 不过每个子被吃之后攻击范围会改变 ...

  10. Lync 2013安装中遇到的关于SQL Mirroring的一次报错的解决

    Problem Description ================= Following the Lync Deployment Wizard to setup Database Mirrori ...