Member-only story
Position, Move and Stretch a UIView with contentMode
Predict what will happen when bounds change
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:
- Be able to create a Single View Application, and this tutorial expects that you are comfortable with Subclassing a UIView, and
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.