Objective-C: Programmatically set UIView alignment without using Storyboard

Objective C: rimuovere da codice i vincoli impostati tramite Storyboard

I recently wrote an article about removing Storyboards constraints programmatically. When you do that, you’ll often also want to replace the removed constraints with new ones: you can do that – programmatically as well – by using the addConstraint method, which allows to set one or more constraints between any two UIView items.

Let’s see some example by taking a standard UIButton item as the first object and its Parent View (or superview, as it is called by Objective-C) as the second one.

How to align an object to its ParentView Center X / Center Y

parent.center.x.center.y
Center X, Center Y

 

 

How to align an object to its ParentView Center X / Top Y

parent.center.x.top.y
Center X, Top Y

 

 

Align an object to its ParentView Left X / Top Y

parent.left.x.top.y
Left X, Top Y

 

I think you got it.

Happy coding!

RELATED POSTS

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies.

View all posts by Ryan