UIKit
The high-level framework that allows developers to create views and UI related components.
It also incorporates some of the low-level APIs into an easier-to-use high-level API.
Quartz 2D
The main engine running under the hood to facilitate drawing in iOS; UIKit uses Quartz.
Core Graphics
A framework that supports the graphics context (more on this later), loading images, drawing images, and so on.
Core Animation
A framework that, as its name implies, facilitates animations in iOS.
绘制字符串
- (void)drawRect:(CGRect)rect{ // Drawing code
UIFont *helveticaBold =
[UIFont fontWithName:@"HelveticaNeue-Bold"
size:40.0f]; NSString *myString = @"Some String";
[myString drawAtPoint:CGPointMake(40, 180) withFont:helveticaBold];
}
UIColor *steelBlueColor = [UIColor colorWithRed:0.3f green:0.4f blue:0.6f alpha:1.0f];
CGColorRef colorRef = [steelBlueColor CGColor];
- (void)drawRect:(CGRect)rect{ // Drawing code
/* Assuming the image is in your app bundle and we can load it */
UIImage *xcodeIcon =
[UIImage imageNamed:@"Xcode.png"];
[xcodeIcon drawAtPoint:CGPointMake(0.0f, 20.0f)];
[xcodeIcon drawInRect:CGRectMake(50.0f, 10.0f, 40.0f,
35.0f)];
}
path和line的区别,lines have to be drawn using paths.定义paths,然后让Core Graphics进行绘制
- (void)drawRect:(CGRect)rect{ // Drawing code
/* Set the color that we want to use to draw the line */
[[UIColor brownColor] set];
/* Get the current graphics context */
CGContextRef currentContext = UIGraphicsGetCurrentContext();
/* Set the width for the line */ CGContextSetLineWidth(currentContext, 5.0f);
/* Start the line at this point */ CGContextMoveToPoint(currentContext, 50.0f, 10.0f);
/* And end it at this point */ CGContextAddLineToPoint(currentContext, 100.0f, 200.0f);
/* Use the context's current color to draw the line */
CGContextStrokePath(currentContext);
}
CGContextSetLineJoin(currentContext,paramLineJoin);
设置path
- (void)drawRect:(CGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, self.bounds.origin.x, self.bounds.origin.y);
CGPathAddLineToPoint(path, NULL, self.bounds.size.width, self.bounds.size.height);
CGPathMoveToPoint(path, NULL, self.bounds.size.width, self.bounds.origin.y);
CGPathAddLineToPoint(path, NULL, self.bounds.origin.x, self.bounds.size.height);
CGContextSetLineWidth(currentContext, 5.0);
[[UIColor purpleColor] set];
CGContextAddPath(currentContext, path);
CGContextDrawPath(currentContext, kCGPathStroke);
CGPathRelease(path);
}
- (void)drawRect:(CGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
CGRect rectangle = CGRectMake(30.0, 30.0, 100.0, 200.0);
CGPathAddRect(path, NULL, rectangle);
[[UIColor blackColor] setStroke];
CGContextSetLineWidth(currentContext, 5.0);
[[UIColor purpleColor] setFill];
CGContextAddPath(currentContext, path);
CGContextDrawPath(currentContext, kCGPathFillStroke);
CGPathRelease(path);
}