Search code examples
iosobjective-cswiftconstraintsnslayoutconstraint

How to use the constraints created from iOS 9 in Objective C?


How to use the constraints created from iOS 9 in Objective C? In Swift this shall be like this:

    button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    button.heightAnchor.constraint(equalToConstant: 100).isActive = true

Solution

  • Are you simply asking for an Objective-C translation of your Swift code?

    [button.centerYAnchor constraintEqualToAnchor:view.centreYAnchor].active = YES;
    [button.heightAnchor constraintEqualToConstant:100].active = YES;
    

    The constraints behave and are used in exactly the same way, regardless of the language you use to create them.