O'Reilly logo

Swift Essentials - Second Edition by Dr. Alex Blewitt

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

Custom graphics with drawRect

Subclasses of UIView can implement their own custom graphics by providing a drawRect method that implements the custom drawing routines. The drawRect method takes a CGRect argument, which indicates the area to draw in. However, the actual drawing commands are performed on a Core Graphics context, which is represented by the CGContext class and can be obtained by a call to UIGraphicsGetCurrentContext.

The Core Graphics context represents a drawable area in iOS, and it is used to print as well as draw graphics. Each view has the responsibility to draw itself; the rectangle will either be the full area (for example, the first time that a view is drawn) or it may be a subset of the area (for example, when a dialog has ...

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