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 ...
随机推荐
- YTU 2616: A代码完善--简易二元运算
2616: A代码完善--简易二元运算 时间限制: 1 Sec 内存限制: 128 MB 提交: 280 解决: 187 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 编写二 ...
- curl 查看网站连接情况
curl -o /dev/null -s -w "nslookup_time :%{time_namelookup}\n time_connect: %{time_connect}\ntim ...
- JSON 之 SuperObject(10): Merge、Clone、ForcePath
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...
- C#发送手机验证码
C#发送手机验证码,平台有很多,我就说说其中的1个平台 测试环境:.net2.0 测试效果:速度还可以,10秒内接收短信 1.去http://www.yuntongxun.com注册,会送8元测试金额 ...
- POJ 3565 Ants (最小权匹配)
题意 给出一些蚂蚁的点,给出一些树的点,两两对应,使他们的连线不相交,输出一种方案. 思路 一开始没想到怎么用最小权匹配--后来发现是因为最小权匹配的方案一定不相交(三角形两边之和大于第三边)--还是 ...
- ecshop 商品详情页显示同类别下的推荐商品
1.打开goods.php文件找到下面代码 $smarty->assign('goods_rank', get_goods_rank($goods_id)); // 商品的销售排名 在上面的代码 ...
- [转载] ubuntu下定制Vim/Gvim及使用技巧
vim是linux下的编辑器之神,是玩linux的必备工具,同样emacs是神的编辑器,两个编辑器是各有千秋,看个人的喜好,青菜萝卜各有所爱.我是比较喜欢vim,用vim编写bash,perl,pyt ...
- JNDI绑定数据库
经过3个多小时的努力,配置JNDI数据源(主要是通过DBCP连接池)终于搞定- 还是Tomcat官方的说明好,不过全是英文的,大概还看得懂. 百度上那么花花绿绿的太多了,一个也没成功!... 本例使用 ...
- Java中数组复制的几种方法
/** * @author zhengbinMac */ public class Test { public static void main(String[] args) { int[] arra ...
- linux中怎样从底部向上查看log文件
对于一些很大的log文件,我们用more查看时会很费劲,没有办法直接跳到末尾再向前查看. 我们可以用less来解决,less查看一个文件时,可以使用类似vi的command命令,在command模式下 ...