问题
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