I am new to Core Graphics and I try to draw circles. They can be transparent (only strokes) and filled with the stroke color. Thus, the method is as follows:
+ (UIImage *)iconImageWithColor: (UIColor *)markColor strokeOnly:(BOOL)strokeOnly { CGRect rect = CGRectMake(0.0f, 0.0f, 20.0f, 20.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGPathRef clippingPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:7.5f].CGPath; CGContextAddPath(context, clippingPath); CGContextClip(context); CGContextSetFillColorWithColor(context, strokeOnly == YES ? [[UIColor clearColor] CGColor] : [markColor CGColor]); CGContextFillRect(context, rect); CGPathRef path = CGPathCreateWithRoundedRect(rect, 10.f, 10.f, NULL); [markColor setStroke]; CGContextAddPath(context, path); CGContextDrawPath(context, kCGPathFillStroke); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }
The result is strange - it seems that the image resolution is very low. Is it possible for the result image to look good on the retina display?
source share