在运行时根据设备更改约束 [英] Change constraints based on device during run time
本文介绍了在运行时根据设备更改约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Storyboard设置我的约束。虽然一切都是完美的,我有一些意见,我想改变只有3.5设备上的约束。
I'm using Storyboard to set my constraints. While everything is perfect, I have a some views where I wish to change the constraints on only 3.5" devices.
这是可能吗? p>
Is this possible? How can I do it?
推荐答案
您可以定义一个宏来确定屏幕大小,如下所示:
You can define a macro to determine the screen size, like the following:
#define isiPhone4 ([[UIScreen mainScreen] bounds].size.height == 480)?TRUE:FALSE
稍后在代码中你可以这样做:
Later in the code you can do something like this:
if (isiPhone4) {
self.constraint.constant = NEW_VALUE;
}
要从代码访问storyboard约束,你应该为他们创建 IBOutlets
(控制+像其他任何东西一样将它们拖到控制器中)。
To access storyboard constraints from code you should make IBOutlets
for them (control+drag them into your controller like anything else).
>
这篇关于在运行时根据设备更改约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文