The UIView class does not set a graphics context, so when I go to get the current context, it comes back as nil. I'm in a method subclassed off of UIView, how may I get the graphics context to be able to simply draw a line? Very new at the x-code game. Any help would be appreciated.
+2
A:
Override the - (void)drawRect:(CGRect)rect
method in your UIView subclass
According to the docs:
Use the
UIGraphicsGetCurrentContext
function to get the current graphics context for drawing that also has the coordinate origin in the upper-left corner.
It sets it up for you before invoking that method.
Squeegy
2010-01-22 23:53:05
+1
A:
The graphics context is only set in the drawRect: method which you will need to override, then do all your drawing in there. As a word of caution do not call drawRect: directly, it will be called automatically when the UIView needs to be displayed. If you want to force a draw send a setNeedsDisplay message to your UIView.
Tyr
2010-01-23 00:19:46
Thanks for the help
Jim B
2010-01-23 03:01:18