IOS6之AutoLayout(三)
来源:互联网 发布:不交钱的网络兼职 编辑:程序博客网 时间:2024/05/22 04:30
IOS6之AutoLayout(一)
http://blog.csdn.net/zfpp25_/article/details/8861221
IOS6之AutoLayout(二)
http://blog.csdn.net/zfpp25_/article/details/8861855
IOS6之AutoLayout(三)
http://blog.csdn.net/zfpp25_/article/details/8861958
IOS6之AutoLayout(四)
http://blog.csdn.net/zfpp25_/article/details/8862040
IOS6之AutoLayout(五)
http://blog.csdn.net/zfpp25_/article/details/8862157
继续介绍Image的相对布局实现:
直接上代码:
@interface ViewController1 (){ float aspect;}@property (nonatomic, strong) UIImageView *imageView;@end- (void)viewDidLoad{ [superviewDidLoad]; self.view.backgroundColor = [UIColorwhiteColor]; UIImage *image = [UIImageimageNamed:@"beautiful_girl.png"]; self.imageView = [[UIImageViewalloc]initWithImage:image]; self.imageView.translatesAutoresizingMaskIntoConstraints =NO; [self.viewaddSubview:self.imageView]; aspect =self.imageView.frame.size.height/self.imageView.frame.size.width; [selfautoLayoutImage];}- (void) autoLayoutImage{//图片的中心点X坐标与self.view的中心点X左边相等 NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self.imageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]; [self.view addConstraint:constraint]; //图片的中心点Y坐标与self.view的中心点Y左边相等 constraint = [NSLayoutConstraint constraintWithItem:self.imageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]; [self.viewaddConstraint:constraint]; //图片的高度和self.view的高度相等 constraint = [NSLayoutConstraint constraintWithItem:self.imageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1.0f constant:0.0f]; [self.viewaddConstraint:constraint]; // 为了保持当屏幕旋转时候,图片的纵横比不变,如果不设置比例,图片比例会改变(multiplier:aspect) constraint = [NSLayoutConstraint constraintWithItem:self.imageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.imageView attribute:NSLayoutAttributeWidth multiplier:aspect constant:0.0f]; [self.imageViewaddConstraint:constraint];}
如果有地方不理解,可以参考IOS6之AutoLayout(一)、IOS6之AutoLayout(二)。
转载请保留,原文链接:http://blog.csdn.net/lizhongfu2013/article/details/8861958
若发现有不合适或错误之处,还请批评指正,不胜感激。
- IOS6之AutoLayout(三)
- IOS6之AutoLayout(三)
- IOS6之AutoLayout(三)
- IOS6之AutoLayout(一)
- IOS6之AutoLayout(二)
- IOS6之AutoLayout(四)
- IOS6之AutoLayout(五)
- IOS6之AutoLayout(一)
- IOS6之AutoLayout(二)
- IOS6之AutoLayout(四)
- IOS6之AutoLayout(一)
- IOS6之AutoLayout(二)
- IOS6之AutoLayout(四)
- IOS6之AutoLayout(五)
- ios6 autoLayout
- AutoLayout(三)
- AutoLayout在iOS6和Xcode5中的应用
- iOS之使用代码实现autolayout中Visual format language(三)
- java 关键字之final
- Hadoop中Mapper类的setup()函数在什么地方调用
- OpenStack Project Architecture Overview
- 黑马程序员_设计模式总结
- JSON java 读取
- IOS6之AutoLayout(三)
- Lesson3: MFC框架程序剖析
- ubuntu64位使用Dr.com客户端上网解决方法
- Lesson4: 简单绘图
- 动态规划解——有向图中的最长路径
- jQuery打印插件JQPRINT
- frame与父页面传值
- Vc 串口编程 Win32 控件
- openstack Conceptual Architecture