自动版式:来源和大小应根据宽度和高度变化的因素 [英] Autolayout: origin and size should change according to width and height factor

查看:349
本文介绍了自动版式:来源和大小应根据宽度和高度变化的因素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个场景我需要的东西。

Here is a scenario what I needed.

我已经把一个UIButton的IB(大小的iPhone4英寸),其初始框架IB是的 X:100,Y:100,W:100,H:100 。我想的起源和高度应根据设备尺寸改变。例如iPhone6​​的宽度和高度为375X667,因此宽度系数(三百二十零分之三百七十五= 1.1718)并高度系数(五百六十八分之六百六十七= 1.1742)。在这个场景我想通过宽度系数(1.1718),以改变我的按钮起源X和宽度与乘法并原点Y和高度乘以高度因子(1.1782)。在这种情况下,我的按钮应显示在 X:100X1.1718,Y:100X1.1742,W:100X1.1718,H:100X1.1742

I have put a UIButton on IB (size iPhone4 inch) whose initial frame on IB is x:100,y:100,w:100,h:100. I want the origins and height should change according to device size. for example the width and height of iPhone6 is 375X667, hence the width factor (375/320=1.1718) and height factor (667/568=1.1742). In this scene I want to change my buttons origin X and width with multiply by width factor (1.1718) and origin Y and height with multiply by height factor (1.1782). In this case my button should be shown on x:100X1.1718, y:100X1.1742, w:100X1.1718, h:100X1.1742 .

需要同样的事情iPhone6​​ +

same thing is needed for iPhone6+.

我可以很容易地通过设置这个面具自动尺寸达到此。如何能够做到通过自动版式一样的吗?我应该遵循什么样的步骤,我应该申请什么限制?

I can easily achieve this by setting This autoresizing masks. How can I achieve the same by using autolayout? What step should I follow, what constraints should I apply?

<一个href=\"http://stackoverflow.com/questions/26881203/autolayout-x$c$c6-need-autolayout-constraints-for-this\">My $ P $这个 pvious问题

我附上一些截图什么,我需要使用自动布局(实现了与上面的图像显示自动尺寸调整面罩)。

I am attaching some screenshots what i needed by using Autolayout (Achieved with autoresizing mask shown in above image).

我的尝试: -

第一步: - 以对IB大小100X100的按钮。设置其X = 100且y = 100。

第二步: - 应用此限制。




Step1:- Take a button of size 100X100 on IB. set its X=100 and y=100. Step2:- applied this constraints.

推荐答案

由于pre你的问题,你可以设置这个限制你的UIButton。

As pre your question you can set this constraints to your UIButton.

不需要你改变你所设定的UIButton的高度和宽度的限制。

You are not required to change the constraint which you have set for height and width of UIButton.

1。)您需要设置的水平空间为 Button.Leading Superview.Trailing

1.) You need to set horizontal space to Button.Leading and Superview.Trailing.

常数= 0 优先= 1000 乘数= 100:320 ,因为我已经设置如下图

Set constant=0, Priority=1000 and Multiplier=100:320 as I've set in below image.

2。)您需要设置的水平空间为 Button.Top Superview.Bottom

2.) You need to set horizontal space to Button.Top and Superview.Bottom.

常数= 0 优先= 1000 乘数= 100:568 ,因为我已经设置如下图

Set constant=0, Priority=1000 and Multiplier=100:568 as I've set in below image.

结果

希望这会解决您的问题。

Hope this solves your problem.

这篇关于自动版式:来源和大小应根据宽度和高度变化的因素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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