Member-only story

Position, Move and Stretch a UIView with contentMode

Predict what will happen when bounds change

Steven Curtis
5 min readMay 26, 2020
Photo by Tiago Felipe Ferreira on Unsplash

I drew a circle using a UIBezierPath in a custom UIView. No problem — except on rotation the circle turned into an oval — less cool.

The solution involved no code at all. You simply set the contentMode to .redraw and.. Solved! Solution from the Storyboard:

But wait. There are 13 different options here. What are they, and what do they do? That’s what this article is about!

Prerequisites:

The example project

We can place a man in an UIImageView using AutoLayout constraints. You’ll also need to have an image called man nestled inside your Asset catalog.

Something like the following:

Now within the viewDidLoad() function of your view controller you can place some code to initialize the UIImageView and the image.

--

--

No responses yet