在运行时改变基于设备的限制 [英] Change constraints based on device during run time

查看:100
本文介绍了在运行时改变基于设备的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用故事板来设置我的约束。虽然一切都是完美的,我有我的地方希望改变的只有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.

这可能吗?我该怎么办呢?

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

后来在code你可以做这样的事情:

Later in the code you can do something like this:

if (isiPhone4) {
    self.constraint.constant = NEW_VALUE;
}

要访问从$ C $故事板的限制c您应该 IBOutlets 它们(控制+将它们拖动到控制器中其他任何事情一样)。

To access storyboard constraints from code you should make IBOutlets for them (control+drag them into your controller like anything else).

这篇关于在运行时改变基于设备的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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