Quartz2D drawRect
Get Context
CGContextRef contex = UIGraphicsGetCurrentContext();
Draw Rect
CGContextAddRect(contex, rect);
[[UIColor colorWithWhite:0.95 alpha:1] set];
CGContextFillPath(contex); // CGContextStrokePath(contex);
Draw Circle
CGContextSetLineWidth(context, 0);
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextBeginPath(context);
CGContextAddEllipseInRect(context, rect);
CGContextDrawPath(context, kCGPathFillStroke);
Draw Circle with UIBezierPath
[[UIColor lightGrayColor] setStroke];
CGPoint center = CGPointMake(baseWidth/2, baseWidth/2);
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:r startAngle:0 endAngle:2*M_PI clockwise:YES];
[path stroke];
Draw Line with UIBezierPath
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:p1];
[path addLineToPoint:p2];
[path stroke];
Draw Text
NSString *text = @"HELLO";
NSMutableParagraphStyle *textStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
textStyle.alignment = NSTextAlignmentCenter;
UIFont *font = [UIFont boldSystemFontOfSize:size];
NSMutableDictionary *dateTextAttrs =[NSMutableDictionary dictionary];
[dateTextAttrs setValue:font forKey:NSFontAttributeName];
[dateTextAttrs setValue:color forKey:NSForegroundColorAttributeName];
[dateTextAttrs setValue:textStyle forKey:NSParagraphStyleAttributeName];
CGSize drawSize = [text sizeWithAttributes:dateTextAttrs];
CGRect textRect = CGRectMake(x, y, rect.size.width, drawSize.height);
[text drawInRect:textRect withAttributes:dateTextAttrs];
View Comments...