The drawRect: Method
So far, you have created a UIView subclass, created two instances of it, and inserted them into the view hierarchy.
We gave these two views instances distinguishable backgroundColors so that we can see their position and size on the screen. But views comprise all iOS interfaces, so clearly there must be a way to draw more than just colored rectangles. The drawing that makes a view interesting happens in the UIView method drawRect:. By default, drawRect: does nothing, but UIView subclasses override this method to perform custom drawing.
When you override drawRect:, you issue drawing instructions that create the image for instances of your UIView subclass. These drawing instructions come from the Core Graphics framework, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access