Subclassing UIView in Swift
Provide the functionality that a standard UIView just can’t
Here are Apple’s Subclassing notes from their documentation:
The
UIView
class is a key subclassing point for visual content that also requires user interactions. Although there are many good reasons to subclassUIView
, it is recommended that you do so only when the basicUIView
class or the standard system views do not provide the capabilities that you need. Subclassing requires more work on your part to implement the view and to tune its performance.
Which is where many stackoverflow posts will point you to. This doesn’t necessarily help that many users, in the way that this guide will with a practical guide as to actually subclass a UIView with examples.
This guide to the rescue!
Difficulty: Beginner | Easy | Normal | Challenging
Prerequisites:
- Some knowledge of OO would be useful (although I’ll take you through the basics here), and I will use Playgrounds (and include this in full at the end) but if you want to see the result of your work press one of the following symbols (the eye or the rectangle) to see it!