did you check context is nil ?
and are you calling UIGraphicsGetCurrentContext() inside of the drawRect method? As far as I know, it can only be called within drawRect, otherwise it will just return nil.
I tried your method add into drawRect method ,it works.
The administrator has disabled public write access.