Cover by Joe Conway, Aaron Hillegass

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required