Change the value of constraint for only iPhone 4 i

2019-09-11 05:10发布

问题:

How I can change the value of a constraint on only one device. For example, I want to display a button with 400px height for all iPhones except iPhone 4 where I would display it with 300px ?

回答1:

The best solution is to create new class inherit from NSLayoutConstraint class and add the properties below, like that you will have the possibility to change the constant, the multiplier and also to deactivate the constraint for each device and all this in the interface builder :

import UIKit

/**
 * This class used to modify easly the constraint for each device iPhone 4, iPhone 5, iPhone 6 or iPhone 6 Plus
 * You can modify the constant, the multiplier and also active / deactive the constraint for each device
 * You should modify this properties only in the storyboard
 */
@IBDesignable
public class LayoutConstraint: NSLayoutConstraint {

    // MARK: