I'm using Core Graphic
library for drawing on UIView
under method drawRect
. As we know, under this method, we firstly get context by:
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
}
I often use helper method for drawing. So, in helper method, should I put this context as parameter. For example:
- drawCircle:(CGContextRef)context center:(int)center radius:(int)radius {
// drawing here
}
Or we can get context variable later in helper function:
- drawCircle: center:(int)center radius:(int)radius {
CGContextRef context = UIGraphicsGetCurrentContext();
// drawing here
}
I have tested and often don't see any problems. But I'm afraid, when I'm calling another method, something changes and UIGraphicsGetCurrentContext()
will return different context variable. So is it safe to do in second way ? Because it will make my code clearer. And if wrong, please tell me will be wrong under what circumstance ?
Thanks :)