IOS Autolayout(VFL) 处理子视图居中
来源:互联网 发布:世界粮农组织数据库 编辑:程序博客网 时间:2024/05/16 12:21
VFL的子视图居中,网上搜了很多都没找到有用代码,自己研究出来了。代码如下
- UIActivityIndicatorView* prgrssView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
- prgrssView.translatesAutoresizingMaskIntoConstraints = NO;
- [self.view addSubview:prgrssView];
- [prgrssView release];
- NSDictionary* views = NSDictionaryOfVariableBindings(prgrssView);
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[prgrssView]-|" options:NSLayoutFormatAlignAllCenterX metrics:nil views:views]];
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[prgrssView]-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:views]];
以上代码测试下来只对UIActivityIndicatorView有效,如果一个view有宽度和高度则上面的居中代码会报错。可以通过另一种方式来处理,具体代码如下
- //beging
- UIImageView* imagevew = [UIImageView autolayoutView];
- [imagevew setContentMode:UIViewContentModeScaleToFill];
- [imagevew setImage:_tabCellImage];
- [imagevew setTag:AEC_TAG_IMAGE_VIEW];
- [self.view addSubview:imagevew];
- [imagevew release];
- NSDictionary* views = NSDictionaryOfVariableBindings(imagevew);
- //设置高度
- [self.view.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[imagevew(60)]" options:0 metrics:nil views:views]];
- //设置宽度
- [self.view.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[imagevew(60)]" options:0 metrics:nil views:views]];
- //垂直居中
- [self.view addConstraint:[NSLayoutConstraint constraintWithItem:imagevew attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]];
- //水平居中
- [self.view addConstraint:[NSLayoutConstraint constraintWithItem:imagevew attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]];
- //end
0 0
- IOS Autolayout(VFL) 处理子视图居中
- IOS Autolayout(VFL) 处理子视图居中
- IOS autoLayout 让视图居中
- VFL 视图居中
- iOS autolayout和VFL
- iOS--VFL--autolayout--自动布局
- iOS 代码添加约束—VFL (AutoLayout)
- iOS 代码添加约束—VFL (AutoLayout)
- iOS 之Autolayout(VFL)(一)
- ios进阶--Autolayout 之VFL语言
- iOS 一一 AutoLayout之VFL实现
- VFL--autolayout
- IOS-AutoLayout居中
- IOS开发笔记之AutoLayout及VFL探索
- iOS 一篇厚道的Autolayout及VFL经验分享
- IOS autoLayout之使用VFL语言进行代码自动布局
- iOS小明开发笔记(二十七) (Autolayout(VFL)一)
- iOS小明开发笔记(二十八) (Autolayout(VFL)二)
- Android-Universal-Image-Loader 图片异步加载类库的使用(超详细配置)
- ng1.3+表单验证<AngularJs>
- java 软引用、弱引用、强引用、虚引用的解析
- C++实验2—学生成绩
- checkio the most frequent weekdays
- IOS Autolayout(VFL) 处理子视图居中
- CActiveXUI的一个Bug
- 关于一个多线程类的设计方法
- HashMap与HashTable解读(一)
- 南阳理工学院个人积分赛第四场【总结】
- 网络图片人脸识别并根据人脸焦点显示图片
- 非数字正则表达式
- Android之Activity跳转方式
- 把一个view上的点转到另一个view坐标系