Syed e Hussaini Syed e Hussaini - 1 day ago 4
iOS Question

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

I have two

UIViews
with parent and child relation to each other. I want to set a trailing space of
childView
to its
parentView
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
StoryBoard
? I can't set that again in program because i have more child views beside.

Answer

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.

Comments