Syed e Hussaini Syed e Hussaini - 1 year ago 74
iOS Question

Give a dynamic value to trailing space of a UIView in StoryBoard

I have two

with parent and child relation to each other. I want to set a trailing space of
to its
with unknown value. When i set the margin with constant value, it always place with that value but i need to place that with the value according to its width. How can i set constraint in
? I can't set that again in program because i have more child views beside.

Answer Source

There are 2 Approaches of achieving this..

1: create an object of your desired constraint using IBOutlet and change the value in the ViewController.m file. for example..

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

Now change the constant value to any desired number. In my case i want to set the trailing space to 3 times 1/4th of the screen width.

self.trailingSpaceConstraint.constant = self.view.frame.size.height/4*3;

2: Select any constraint and navigate to property attribute and change the value according to Add Side Class Customization by clicking the + sign left to the constant field in that property attribute section of any constraint.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download