O'Reilly logo

iOS Programming: The Big Nerd Ranch Guide, 6th Edition by Aaron Hillegass, Christian Keur

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Programmatic Constraints

In Chapter 3, you learned about Auto Layout constraints and how to add them using Interface Builder. In this section, you will learn how to add constraints to an interface programmatically.

Apple recommends that you create and constrain your views in Interface Builder whenever possible. However, if your views are created in code, then you will need to constrain them programmatically. The interface for MapViewController is created programmatically, so it is a great candidate for programmatic constraints.

To learn about programmatic constraints, you are going to add a UISegmentedControl to MapViewController’s interface. A segmented control allows the user to choose between a discrete set of options, and you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required