IOS之AutoLayout
来源:互联网 发布:怎么阅读spring源码 编辑:程序博客网 时间:2024/05/17 12:47
个人感觉,现阶段IOS开发必备技能—–AutoLayout。苹果公司也一直在推荐这个布局方法。现在我们来简单了解一下。直接上代码:
UIView *backgroundView = [[UIView alloc] init]; [backgroundView setTranslatesAutoresizingMaskIntoConstraints:NO]; backgroundView.backgroundColor = [UIColor blueColor]; [self.view addSubview:backgroundView]; //UILabel UILabel *textInfoLabel = [[UILabel alloc] init]; [textInfoLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; textInfoLabel.backgroundColor = [UIColor redColor]; textInfoLabel.numberOfLines = 0; textInfoLabel.font = [UIFont systemFontOfSize:15]; textInfoLabel.text = @"测试"; [self.view addSubview:textInfoLabel]; NSDictionary *views = @{@"backgroundView":backgroundView, @"textInfoLabel":textInfoLabel}; NSDictionary *metrics = @{@"LeftStep":@20, @"TopStep":@30, @"Width":@200, @"Height":@"100", @"VStep":@20, @"HStep":@20};//垂直方向 @“垂直方向:|-距离顶部-[backgroundView(==Width)]-两个view之间的垂直距离-[textInfoLabel(>=一行字的高度)]” NSString *vLayoutString = @"V:|-TopStep-[backgroundView(==Width)]-VStep-[textInfoLabel(>=20)]"; NSArray *vLayoutArray = [NSLayoutConstraint constraintsWithVisualFormat:vLayoutString options:0 metrics:metrics views:views]; //水平方向 @"水平方向:|-距离左边-[backgroundView(==水平高度(宽度))-两个view之间的水平距离-[]] NSString *hLayoutstring = @"H:|-LeftStep-[backgroundView(==Height)]-HStep-[textInfoLabel(==120)]"; NSArray *hLayoutArray = [NSLayoutConstraint constraintsWithVisualFormat:hLayoutstring options:0 metrics:metrics views:views]; [self.view addConstraints:vLayoutArray]; [self.view addConstraints:hLayoutArray];
0 0
- iOS UI 之AutoLayout
- iOS学习之Autolayout
- IOS之AutoLayout
- iOS 之autolayout
- IOS之Autolayout简单实用
- iOS开发之autoLayout constraint
- iOS Autolayout之Masonry解读
- iOS Autolayout之Masonry解读
- iOS Autolayout之Masonry解读
- iOS Autolayout之Masonry详解
- ios之Autolayout的运用
- ios开发autolayout之代码实现Autolayout使用总结
- iOS适配之autolayout和sizeclass
- iOS学习之AutoLayout常用方法
- iOS开发技巧之autolayout自动布局
- iOS开发之 AutoLayout自动布局
- iOS 开发之 AutoLayout 自动布局
- iOS 之Autolayout(VFL)(一)
- 黑马程序员——Java基础---静态代码块和构造方法执行顺序
- Ubuntu 14.04下为Virtualbox 4.3.20开启usb设备支持
- 第三章:UVa1586 解题报告
- 用Docker快速打造企业虚拟化云计算Paas平台(2天)
- 云计算虚拟化Docker企业级最佳实践
- IOS之AutoLayout
- 【linux】U-BOOT与linux kernel通信: struct tag
- 使用repo和git下载android源码 和 相关解释
- git使用小结
- Unity脚本的生命周期
- 第三章:UVa1585 解题报告
- You can't operate on a closed Connection!!!
- 想知道Android应用吃掉了多少电,怎么破?
- 目的:使用bbed将已经offline掉的datafile 5 的scn信息改为与其他datafile一致。