You have no valid graphics context. UIGraphicsGetCurrentContext() obviously returned nil.

Where do you want to draw to?

If you want to draw to the screen, then you should implement the drawRect: method of UIView or one of its subclasses and have iOS call that method (by triggering a refresh of part of your screen). Then you will have a valid graphics context during the execution of drawRect:.

If you want to draw to an offscreen pixel map, then you have to create a graphics context yourself with UIGraphicsBeginImageContext or a similar function.

EDIT:

So for drawing into a UIView, you need to create a UIView subclass and override drawRect: