Change constraints based on device during run time

試著忘記壹切 提交于 2019-12-10 21:14:45

问题


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?


回答1:


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;
}

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



来源:https://stackoverflow.com/questions/21748156/change-constraints-based-on-device-during-run-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!