什么是iOS的equivillant到Android布局权重? [英] What is the iOS equivillant to Android layout weights?

查看:235
本文介绍了什么是iOS的equivillant到Android布局权重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是Android开发的iPhone和iPad产品我试图模仿一些我在过去的应用中所做的布局,而是现在。的东西,我在Android中经常使用的是布局重量。我做了一吨的搜索,阅读书籍,博客,我想这样的事情有可能在iOS中6,但我一直没能找到任何东西。我也试着看一吨的在iOS的自动布局教程,但我真的没有发现任何东西,完成我的任务。这是推动我坚果。所以...有没有的iOS相当于一个到Android布局权重?

Coming from Android development I'm trying to imitate some of the layouts that I've made in past applications, but now on the iPhone and iPad. Something that I use quite often in Android is layout weight. I've done a ton of searching, reading books, blogs, and I thought something like this would be possible in iOS 6, but I haven't been able to find anything. I've also tried watching a ton of tutorials on auto layout in iOS, but I really haven't found anything that accomplishes my task. This is driving me nuts. So... is there an iOS equivalent to Android layout weights?

推荐答案

布局权重是一个什么样的iOS 6的自动布局框架可以做一个子集。不幸的是,在榫文件设置限制在X code进行痛苦4.我建议设立限制在笔尖只有当你有机会获得X code 5开发preVIEW。

"Layout weights" is a subset of what iOS 6's Auto-layout framework can do. Unfortunately, setting up constraints in nib files are a pain in XCode 4. I recommend setting up constraints in nib only if you have access to the XCode 5 dev preview.

不过,你提到的情况可能不会自动布局完成所有:

But, the scenario you mentioned can be done without auto-layout at all:

如果我想两个视图,顶视图将是一个套的高度   (200),然后我想另一个视图占用的休息   可用空间。我能做到这一点在Interface Builder?

What if I wanted two views, and the top view would be a "set" height (200) and then I wanted another view to take up the rest of the available space. Could I do that in interface builder?

当然可以。刚去的尺寸检查,并设置顶视图的弹簧和 - 支柱,以

Yes you can. Just go to the Size Inspector and set the top view's springs-and-struts to

和底部的以

(注意红叉。)

更新:

OK,如果你真的想使用自动布局:

OK, if you really want to use autolayout:

UIView *topView = ...;
UIView *bottomView = ...;
NSDictionary *bindings = NSDictionaryOfVariableBindings(topView, bottomView);
[self.view addConstraints:
 [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[topView(200)][bottomView]|"
                                         options:(NSLayoutFormatAlignAllLeft | NSLayoutFormatAlignAllRight)
                                         metrics:nil
                                           views:bindings]];

这篇关于什么是iOS的equivillant到Android布局权重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆