IOS自动布局
- (void)viewDidLoad
{
[super viewDidLoad]; [self addNavigationBar:FEEDBACK_VIEW_CONTROLLER]; UILabel *note = [[UILabel alloc] init];
[note setText:@"欢迎提出宝贵意见!您留下的每一份心意都将浇灌母婴宝的茁壮成长。"];
[note setLineBreakMode:NSLineBreakByWordWrapping];
note.numberOfLines = 0;
[self.view addSubview:note]; //将自适应向布局约束的转化关掉(根据情况有时需要有时不需要)
[note setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:note
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:navBar
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:10]]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:note
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:10]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:note
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:-10]];
UITextView *tfContent = [[UITextView alloc] init];
[tfContent setTranslatesAutoresizingMaskIntoConstraints:NO];
[tfContent setBackgroundColor:[UIColor whiteColor]];
[tfContent setReturnKeyType:UIReturnKeyDone];
[self.view addSubview:tfContent]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:tfContent
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:note
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:10]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:tfContent
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:10]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:tfContent
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:-10]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:tfContent
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:100]]; UITextField *tfEmail = [UITextField new];
[tfEmail setTranslatesAutoresizingMaskIntoConstraints:NO];
[tfEmail setBackgroundColor:[UIColor whiteColor]];
[tfEmail setClearButtonMode:UITextFieldViewModeAlways];
[tfEmail setReturnKeyType:UIReturnKeyDone];
[tfEmail setPlaceholder:@"请输入邮箱,以便我们联系你!"];
[self.view addSubview:tfEmail]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:tfEmail
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:tfContent
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:10]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:tfEmail
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:10]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:tfEmail
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:-10]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:tfEmail
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:35]]; UIButton *btnSubmit = [[UIButton alloc] init];
[btnSubmit setTranslatesAutoresizingMaskIntoConstraints:NO];
[btnSubmit setTitle:STRING_COMMON_SUBMIT forState:UIControlStateNormal];
[btnSubmit setBackgroundImage:[UIImage imageNamed:@"bg_red_orange"] forState:UIControlStateNormal];
[btnSubmit setBackgroundImage:[UIImage imageNamed:@"bg_red"] forState:UIControlStateHighlighted];
[self.view addSubview:btnSubmit]; NSMutableArray *tmpConstraints = [NSMutableArray array]; [tmpConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[tfEmail]-10-[btnSubmit(==35)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(tfEmail,btnSubmit)]];
[tmpConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[btnSubmit]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(btnSubmit)]];
[self.view addConstraints:tmpConstraints]; }

IOS自动布局的更多相关文章
- iOS 自动布局详细介绍
1. 自动布局的理解 iOS自动布局很有用,可以在不同size的屏幕上运行,原先看的头痛,还是习惯用最蠢的[UIScreen mainScreen].bounds.size.width等来布局,后来实 ...
- iOS自动布局——Masonry详解
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由鹅厂新鲜事儿发表于云+社区专栏 作者:oceanlong | 腾讯 移动客户端开发工程师 前言 UI布局是整个前端体系里不可或缺的一环 ...
- 掌握iOS自动布局
1,自动布局是一种基于约束的布局(constraint-based layout)引擎,它可以根据开发者在对象上的约束自动调整大小与位置. 2.在iOS 6之前使用的布局模型是“spring& ...
- iOS自动布局之autoresizingi
对于iOS的app开发者来说,不会像Android开发者一样为很多的屏幕尺寸来做界面适配,因此硬编码的坐标也能工作良好,但是从设计模式上来说这不是好的做法.而且也还有一些问题,如iPhone5的适配, ...
- 学会爱上iOS自动布局(Auto Layout) - 剑尖
本文翻译自Yari Dareglia的LEARN TO LOVE AUTO LAYOUT文章先生们,女士们,让我们以正确的心态开始本教程吧:自动布局就是简单!我花了一段时间来掌握自动布局是如何工作的, ...
- iOS 自动布局过程
自动布局将视图显示在屏幕上的步骤: 更新约束,它会从子视图传递到父视图,设置布局信息:约束更新时自动触发setNeedsUpdateConstraints:updateConstraints可以增加本 ...
- iOS 自动布局框架 – Masonry 详解
目前iOS开发中大多数页面都已经开始使用Interface Builder的方式进行UI开发了,但是在一些变化比较复杂的页面,还是需要通过代码来进行UI开发的.而且有很多比较老的项目,本身就还在采用纯 ...
- iOS自动布局框架-Masonry详解
首先,在正式使用Masonry之前,我们先来看看在xib中我们是如何使用AutoLayout 从图中我们可以看出,只要设置相应得局限,控制好父视图与子视图之间的关系就应该很ok的拖出你需要的需 ...
- IOS 自动布局-UIStackPanel和UIGridPanel(四)
为什么说scrollview的自动化布局是难点? 对scrollview做自动化布局,无非就是想对scrollview里面的subviews来做自动化布局.但是scrollview里面的subview ...
随机推荐
- (九)ASP.NET自定义用户控件(2)
http://www.cnblogs.com/SkySoot/archive/2012/09/04/2670678.html 用户控件 在 .NET 里,可以通过两种方式把自己的控件插入到 Web 窗 ...
- jsp+servlet+jquery 用jquery uploadify最新版本实现多文件上传
//这是script代码 <link rel="stylesheet" type="text/css" href="uploadify/uplo ...
- 《c程序设计语言》读书笔记--首次输入不能是空符;最多10个字符
#include <stdio.h> #define Num 10 int main() { int wor = 0; int arr[Num] = {0}; int c,count = ...
- springMVC实现多文件上传
<h2>上传多个文件 实例</h2> <form action="/workreport/uploadMultiFile.html" method=& ...
- UVa 136 Ugly Numbers【优先队列】
题意:给出丑数的定义,不能被除2,3,5以外的素数整除的的数称为丑数. 和杭电的那一题丑数一样--这里学的紫书上的用优先队列来做. 用已知的丑数去生成新的丑数,利用优先队列的能够每次取出当前最小的丑数 ...
- 30条MySQL优化总结
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...
- 设置sudo不输入密码 sudoers 编辑出错后的补救方法
一 设置sudo为不需要密码 有时候我们只需要执行一条root权限的命令也要su到root,是不是有些不方便?这时可以用sudo代替.默认新建的用户不在sudo组,需要编辑/etc/sudoers文件 ...
- unity3d 破解安装
1.下载破解程序,执行生成unity_v4.x.ulf文件 2.断网 3.执行unity客户端,load该lisence文件即可 注意:安装unity客户端完成后,未破解,切记别打开unity客户端
- HDU 5319 Painter (模拟)
题意: 一个画家画出一张,有3种颜色的笔,R.G.B.R看成'\',B看成'/',G看成这两种的重叠(即叉形).给的是一个矩阵,矩阵中只有4种符号,除了3种颜色还有'.',代表没有涂色.问最小耗费多少 ...
- Scrum&Kanban在移动开发团队的实践 (二)
Scrum&Kanban在移动开发团队的实践系列: Scrum&Kanban在移动开发团队的实践 (一) Scrum&Kanban在移动开发团队的实践 (二) 在第一篇分享文章 ...