Site icon Ryadel

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

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!

Exit mobile version