创建基于百分比的iOS布局 [英] Creating a percentage based iOS layout

查看:99
本文介绍了创建基于百分比的iOS布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试复制我目前在Android应用程序中使用的布局,但我不知道如何在iOS中进行此操作,尤其是因为iPhone 5的高度。

I'm trying to replicate a layout that I currently have in an Android application, but I don't know how to go about it in iOS especially because of the tallness of the iPhone 5.

我知道如何用Android术语来解释这个问题,但过去几天我一直在努力尝试在iOS上这样做,但我无法让它发挥作用。

I know how to explain this in "Android" terms but I've been trying for the past few days to do this in iOS but I can't quite get it to work.

解释它的最佳方式:


  1. 我想要两种布局。顶部布局必须占40%,底部必须占60%。

  2. 在顶部布局中,它们必须是三个按钮,填满所有可能的空间(基本上是1/3)空格)

  3. 在底部布局中,我想要一个imageView,然后是一个textView。

这是一个油漆样机。这可以在iOS中做到吗?我觉得布局比Android更难创建。

This is a paint mockup. Is this possible to do in iOS? I feel that layouts are much harder to create than android.

推荐答案

使用Xcode 6.0,您现在可以在Interface Builder中指定比例宽度或高度。
超级视图的百分比高度的步骤:

Using Xcode 6.0, you can now specify proportional width or height in Interface Builder. Steps for percentage height from superview:

虽然选择了子视图及其超级视图,但添加等高约束(或等宽)如果你希望有一个比例宽度)。

While both the child view and its superview are selected, add an "equal height" constraint (or "equal width" if you wish to have a proportional width).

然后将刚添加的约束的乘数更改为您需要的比例。例如,对于50%,将其更改为2.

Then change the "multiplier" of the constraint you just added to the proportion you need. For example, for 50%, change it to 2.

如果要将内部视图指定为超级视图的百分比,则可以反转约束中的项目:

If you like to specify the inner view as percentage of the superview, you can reverse the items in the constraint:

现在你可以使用0.5的乘数(或你需要的任何其他比例):

Now you can use a multiplier of 0.5 (or any other proportion you need):

在特定情况下,您可以定义相等高度 2个子视图之间的约束,并将乘数更改为1.5(底部为顶部大小的1.5)或0.6667(如果项目相反)。

In your specific case, you can define an "equal height" constraint between the 2 child views, and change the multiplier to 1.5 (the bottom being 1.5 the size of the top) or 0.6667 if the items are reversed.

这篇关于创建基于百分比的iOS布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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