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. 打印 Go 结构体(struct)信息:fmt.Printf("%+v", user)

    package main import "fmt" // 用户 type User struct { Id int Name string Age int } func main( ...

  2. python服务端内存泄露的处理过程

    http://xiaorui.cc http://xiaorui.cc/2017/08/20/python服务端内存泄露的处理过程/

  3. [Bug]Unable to start process dotnet.exe

    This morning I did a sync of a repo using of Visual Studio and then tried to run a web application I ...

  4. SpringBoot 中使用 @Value 为 static 变量赋值

    原文:https://www.jianshu.com/p/ea477fc9abf7 例如: public class Utils { @Value("${test.host}") ...

  5. 【POI】maven引用POI的依赖,XSSFWorkbook依旧无法使用的问题。

    maven项目引用POI的jar: <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> <dependenc ...

  6. Ioc:The basic pattern for integrating Autofac into your application

    The basic pattern for integrating Autofac into your application is: Structure your app with inversio ...

  7. UIWebView加载CSS样式的html

    UIWebView加载CSS样式的html 效果 源码 // // ViewController.m // CSS // // Created by YouXianMing on 16/7/19. / ...

  8. 闪电侠第四季/全集The Flash迅雷下载

    闪电侠第四季>(The Flash Season 4)是DC娱乐和华纳联手CW电视台制作的真人超级英雄系列剧,是美剧<闪电侠>系列的第四季. 该季于2017年10月10日在美国CW电 ...

  9. 用Handler的post()方法来传递线程中的代码段到主线程中执行

    自定义的线程中是不能更新UI的,但是如果遇到更新UI的事情,我们可以用handler的post()方法来将更新UI的方法体,直接传送到主线程中,这样就能直接更新UI了.Handler的post()方法 ...

  10. [Android Security] 如何把java代码转换成smali代码

    copy :https://www.cnblogs.com/gordon0918/p/5466514.html 1.概述 Smali是Android系统中Dalvik虚拟机指令语言,在apk逆向过程中 ...