FROM THE ARCHIVES OF PRAGPUB MAGAZINE, JUNE 2018

Auto Layout, Playgrounds, and Xcode: When to Leave the Playground

by Erica Sadun

PragPub
The Pragmatic Programmers
4 min readOct 6, 2021

--

📚 Connect with us. Want to hear what’s new at The Pragmatic Bookshelf? Sign up for our newsletter. You’ll be the first to know about author speaking engagements, books in beta, new books in print, and promo codes that give you discounts of up to 40 percent.

Our favorite Swift wizard turns the answer to a question about centering a view into high-level content mode advice on when to use or not to use playgrounds.

Recently, someone asked what the easiest way was to center a view (specifically a UIImageView) inside a parent view with minimum offsets from the top and sides.

Photo by Power Lai on Unsplash

Because you’re working with image views, it’s important that you first set the For insets, it’s almost always best to go with a “fitting” aspect-scale, which preserves the entire picture even if it has to pillarbox or letterbox

(Pillarboxing adds extra spacing to each side for tall images; letterboxing adds the top and bottom for wide ones.)

--

--

PragPub
The Pragmatic Programmers

The Pragmatic Programmers bring you archives from PragPub, a magazine on web and mobile development (by editor Michael Swaine, of Dr. Dobb’s Journal fame).