iDev's answer is excellent, but if you need transparent background, then except
UIGraphicsBeginImageContext(view.bounds.size);
you should use
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0);
By default image context is created with opaque == YES, so you have to change it to NO.