IOS布局笔记一(代码实现自动布局)
2014-04-21 17:54
495 查看
1.将一个试图放置在其父视图的中央位置,使用限制条件。
2.创建两个限制条件:一个是将目标视图的 center.x 位置排列在其父视图的 center.x 位置,并且另外一个是将目标视图的 center.y 位置排列在其父视图的 center.y 位置。
3.首先在 WildCatViewController.h中添加一个Button
在.m文件中实现:
不要忘记更改设备可以旋转方向,
运行结果如下图:
本文转自:http://1.wildcat.sinaapp.com/?p=42
限制条件和他们要添加到的视图的关系图如下:
转载请注明:版权所有点击打开链接
接下来学什么:IOS布局笔记二( Visual Format Language 定义水平和垂直约束)
2.创建两个限制条件:一个是将目标视图的 center.x 位置排列在其父视图的 center.x 位置,并且另外一个是将目标视图的 center.y 位置排列在其父视图的 center.y 位置。
3.首先在 WildCatViewController.h中添加一个Button
// // WildCatViewController.h // AutoLayoutDemo // // Created by wildcat on 14-4-20. // Copyright (c) 2014年 com.wildcat. All rights reserved. // #import <UIKit/UIKit.h> @interface WildCatViewController : UIViewController @property(nonatomic,strong) UIButton*button; @end
在.m文件中实现:
// // WildCatViewController.m // AutoLayoutDemo // // Created by wildcat on 14-4-20. // Copyright (c) 2014年 com.wildcat. All rights reserved. // #import "WildCatViewController.h"@interface WildCatViewController () @end @implementation WildCatViewController @synthesize button=_button; - (void)viewDidLoad { [super viewDidLoad]; _button=[UIButton buttonWithType:UIButtonTypeRoundedRect]; _button.translatesAutoresizingMaskIntoConstraints=NO; [_button setTitle:@"WildCat" forState:UIControlStateNormal]; [self.view addSubview:_button]; UIView *superView=_button.superview; //添加约束,使按钮在屏幕水平方向的中央 NSLayoutConstraint *centerXContraint=[NSLayoutConstraint constraintWithItem:_button attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0]; //添加约束,使按钮在屏幕垂直方向的中央 NSLayoutConstraint *centerYContraint=[NSLayoutConstraint constraintWithItem:_button attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0]; //给button的父节点添加约束 [superView addConstraints:@[centerXContraint,centerYContraint]]; } -(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskAll; //屏幕可以旋转 } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
不要忘记更改设备可以旋转方向,
运行结果如下图:
本文转自:http://1.wildcat.sinaapp.com/?p=42
限制条件和他们要添加到的视图的关系图如下:
转载请注明:版权所有点击打开链接
接下来学什么:IOS布局笔记二( Visual Format Language 定义水平和垂直约束)
相关文章推荐
- iOS开发笔记--使用Auto Layout中的VFL(Visual format language)--代码实现自动布局
- iOS开发笔记--使用Auto Layout中的VFL(Visual format language)--代码实现自动布局
- iOS开发笔记--使用Auto Layout中的VFL(Visual format language)--代码实现自动布局
- iOS开发笔记--使用Auto Layout中的VFL(Visual format language)--代码实现自动布局
- iOS开发笔记--使用Auto Layout中的VFL(Visual format language)--代码实现自动布局
- 关于iOS代码实现自动布局
- IOS Auto Layout代码实现自动布局--NSLayoutConstraint
- ios代码实现Autolayout(自动布局)的简单讲解
- iOS学习笔记03——以编码的方式实现Auto Layout自动布局(二)
- iOS学习笔记02——以编码的方式实现Auto Layout自动布局(一)
- ios中纯手写代码怎么实现控件的自动布局(约束)
- IOS代码实现自动布局
- iOS: 学习笔记, 用代码驱动自动布局实例
- [置顶] iOS 兄弟控件的 自动布局实现N等分且宽高比例是1:N(xib 上实现) 代码很简单就不多说
- IOS 代码实现自动布局(视图尺寸自动调整)
- IOS Auto Layout代码实现自动布局--VFL(Visual format language)
- ios中纯手写代码怎么实现内容的自动布局
- [IOS]NSLayoutConstraint-代码实现自动布局的函数用法说明
- iOS: 学习笔记, 用代码驱动自动布局实例(swift)
- iOS-NSLayoutConstraint-代码实现自动布局的函数用法说明