dgee4
dgee4

Reputation: 381

Xcode iOS constraints linked to variables

I was wondering whether it was possible to set constraints which reference a variable and adjust dynamically according to an integer or float value?

Thanks D

Upvotes: 0

Views: 524

Answers (1)

Nik Yekimov
Nik Yekimov

Reputation: 2697

First of all, you should declare outlet

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *view1TopConstraint;

Then you should link this outlet in interface builder like you link any other outlets.

Finally, in your code where it is necessary, do:

view1TopConstraint.constant = 50.f;

Of course everything depends on complexity of your logic, somewhere this approach is simpler, but in big things you'd better to use VFL. See https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html

Upvotes: 1

Related Questions