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

Center X, Center Y



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

Center X, Top Y



Align an object to its ParentView Left X / Top Y

Left X, Top Y


I think you got it.

Happy coding!

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. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.