Hi Readers,
This Post is just a brief introduction about How we can implement Autolayout Contraints through coding.
Now,Before moving ahead with the topic let us have a brief about AutoLayout.
WHAT IS AUTOLAYOUT...??
Auto Layout is a way to define relationships between elements. In Auto Layout we can describe how views and the controls are related to each other because of it's flexible and powerful system.
We can get an incredible control over layout, with a wide range of customization, and create a perfect interface only with the help of Auto Layout.
NOW,LETS IMPLEMENT AUTOLAYOUT THROUGH CODE---!!
* Creating a Contraint
NSLayoutConstraint *myConstraint =[NSLayoutConstraint
constraintWithItem:mylabel
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:superview
attribute:NSLayoutAttributeCenterY
multiplier:1.0
constant:0];
[superview addConstraint:myConstraint];
Above,we have created a Constraint named myContraint on a label named my label
* Removing a Contraint
[superview removeconstraint:myConstraint];
if you want to remove a contraint simply use the above line .
Thanx For Reading
Keep Coding..:)
0 Comment(s)