如何使用自动版式创建总宽度的百分比是多少? [英] How to create percentage of total width using autolayout?

查看:128
本文介绍了如何使用自动版式创建总宽度的百分比是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要建立三个动态列,每一列的总宽度的一个固定百分比。不三分之二,但不同的值。例如,下面的图显示了三列:第一个是42%宽,第二个是25%宽,第三个是33%宽

I need to create three dynamic columns, each with a fixed percentage of the total width. Not thirds, but different values. For example, the following illustration shows three columns: the first being 42% wide, the second being 25% wide, and the third being 33% wide.

有关跨越的ViewController 600像素,这将是252,150,分别198像素。

For a 600 pixel across viewcontroller, that would be 252, 150, and 198 pixels respectively.

然而,对于任何后续的显示尺寸(即iPhone 4的景观(960宽)或iPad 2的纵向(768宽),我想相对百分比是一样的(而不是上面引述的像素宽度)。

However, for any subsequent display sizes (i.e. iPhone 4 landscape (960 wide) or iPad 2 portrait (768 wide), I would like the relative percentages to be the same (not the pixel widths quoted above).

有没有办法做到这一点使用故事板(即没有$ C $三)?我可以在code很容易地做到这一点,但我的目标是尽可能多的这种显示逻辑尽可能的投入到故事板。

Is there a way to do this using Storyboards (i.e. without code)? I can do this easily in code, but my goal is to put as much of this display logic as possible into the Storyboard.

推荐答案

如果像你说的,你知道怎么做,在code,那么你已经知道如何做到这一点的故事板。这是完全一样的限制,但你正在创建它们在视觉上,而不是在code。

If, as you say, you know how to do it in code, then you already know how to do it in the storyboard. It's exactly the same constraints, but you are creating them visually rather than in code.


  1. 选择既是视图和它的父。

  1. Select both a view and its superview.

选择编辑 - >针 - >宽度同样约束宽度等于上海华的宽度(实际上是在画布底部的针弹出的对话框中效果最好在这里)。

Choose Editor -> Pin -> Widths Equally to constrain the width to be equal to the superview's width (actually the "pin" popup dialog at the bottom of the canvas works best here).

编辑约束,并设置乘数为所需的分数,例如0.42。因此也为其他的看法。

Edit the constraint and set the Multiplier to the desired fraction, e.g. 0.42. And so too for the other views.

一张照片是胜过千言万语,我已经实现了你提出的布局你一个故事板,不使用code,在github上的项目,您可以下载并检查:

One picture being worth a thousand words, I've implemented your proposed layout for you in a storyboard, using no code, in a github project that you can download and examine:

<一个href=\"https://github.com/mattneub/percentageWidthsInStoryboard\">https://github.com/mattneub/percentageWidthsInStoryboard

这篇关于如何使用自动版式创建总宽度的百分比是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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