美文网首页
菜鸟教程——iOS CoreGraphics绘制图像

菜鸟教程——iOS CoreGraphics绘制图像

作者: iOS谢先森 | 来源:发表于2017-06-28 13:39 被阅读0次

可参照之前的iOS UIKit绘图,只是使用CoreGraphics中方法绘制

1.- (void)drawRect:(CGRect)rect

#pragma mark -----CoreGraphics

- (void)drawRect:(CGRect)rect{

//当前上下文及画布为当前view

CGContextRef con = UIGraphicsGetCurrentContext();

CGContextAddEllipseInRect(con, CGRectMake(0,0,100,100));

CGContextSetFillColorWithColor(con, [UIColor blueColor].CGColor);

CGContextFillPath(con);

}

2.- (void)drawInContext:(CGContextRef)ctx

#pragma mark -----CoreGraphics

//- (void)drawInContext:(CGContextRef)ctx{

//

//    CGContextAddEllipseInRect(ctx, CGRectMake(0,0,100,100));

//

//    CGContextSetFillColorWithColor(ctx, [UIColor blueColor].CGColor);

//

//    CGContextFillPath(ctx);

//}

3.- (void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx

#pragma mark --- coreGraphics

//- (void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx {

//

//    CGContextAddEllipseInRect(ctx, CGRectMake(0, 0, 100, 100));

//    CGContextSetFillColorWithColor(ctx, [UIColor blueColor].CGColor);

//    CGContextFillPath(ctx);

//

//

//}

4.UIGraphicsBeginImageContextWithOptions

#pragma  mark ----- coreGraphics

//    UIGraphicsBeginImageContextWithOptions(CGSizeMake(100,100), NO, 0);

//

//    CGContextRef con = UIGraphicsGetCurrentContext();

//

//    CGContextAddEllipseInRect(con, CGRectMake(0,0,100,100));

//

//    CGContextSetFillColorWithColor(con, [UIColor blueColor].CGColor);

//

//    CGContextFillPath(con);

//

//    UIImage* img = UIGraphicsGetImageFromCurrentImageContext();

//    UIGraphicsEndImageContext();

github下载地址

相关文章

网友评论

      本文标题:菜鸟教程——iOS CoreGraphics绘制图像

      本文链接:https://www.haomeiwen.com/subject/edducxtx.html