Member-only story
Why Use LayoutSubviews Anyway?
It works…
I previously wrote an article about the view drawing cycle, yet this turned out to be insufficient when I needed some help with shadows in a UITableViewCell
subclass.
So I felt like more guidance should be out there around layoutSubviews
. This article is the result of my investigation!
Before we start
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 12.5, and Swift 5.4
Prerequisites
- You’ll need to either be able to write an iOS application or write some Swift code in Playgrounds
Keywords and Terminology
layoutSubview: A function containing code called when the view is resized
This article
Background
The view lifecycle is extremely important especially while subclassing UIView
. However I wanted to add shadows to my UITableView
. What could possibly go wrong?
The failed attempt
I set up a UITableView
like in the following example article and added a shadow around the UIImageView
on the left-hand side.