Possible Duplicate:
Drawing shape iOS
CGContextRef, CGPoint, and CGSize
I am trying to use a current method where I have to include the CGContextRef, CGPoint, and CGSize:
CGPoint p1 = {10, 10};
CGSize size;
CGContextRef context = UIGraphicsGetCurrentContext();
[self drawArrowWithContext:context atPoint:p1 withSize:size lineWidth:400 arrowHeight:400];
When I run the application I get this error:
Jan 21 21:41:56 Alexs-ipad Splash-it[1497] : CGContextDrawPath: invalid context 0x0
The problem must be in the context, but I can’t find anywhere on the internet the solution to the problem. This whole code should call a method for drawing an arrow.
Thanks for any help.
In order to return a valid context you have to be in the appropriate area.
That basically means this code needs to be in
drawRect:or you need to create an image context usingUIGraphicsBeginImageContextUpdate: the DrawRect:
The
drawRect:is a special method called for each UIView that gives you an access point to do custom drawing using Core Graphics. The most common use for this is to create a custom UIView object in your case anArrowView. Then in that you would overridedrawRect:using your code.Update: the image context
A secondary way to tap into custom Core Graphics drawing is to create an imageContext then harvest its results.
So you’d start by creating an image context, running your drawing code, then converting that into an UIImage you can add to your existing views.