画图1

基础知识


//系统内部绘图的方法视图,设置frame时才会调用

- (void)drawRect:(CGRect)rect {

// Drawing code

//[super drawRect:rect];

//画一条线

//创建一个绘图缓冲区域

CGContextRef context =UIGraphicsGetCurrentContext();

//设置画笔的线的宽度和颜色及边帽

{

//宽度

CGContextSetLineWidth(context, 8);

//颜色

CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);

//边帽设置,边帽可以是线条不会出现裂痕

CGContextSetLineCap(context,kCGLineCapRound);

//线的结合部分的样式

CGContextSetLineJoin(context,kCGLineJoinRound);

}

//画一条线

//    //起点

//    CGContextMoveToPoint(context, 20, 80);

//    //终点

//    CGContextAddLineToPoint(context, 100, 180);

//    CGContextAddLineToPoint(context, 180, 80);

//    //封闭区域(三角形)

//    CGContextClosePath(context);

//    //圆形

//    CGContextAddArc(context, 200, 200, 100, 0, M_PI*2, 1);

//    //设置填充色

////    [[UIColor orangeColor] set];

//    CGContextSetRGBFillColor(context, 0, 1, 0, 1);

//    //填充颜色

//    CGContextFillPath(context);

//    //椭圆

//    //CGContextAddEllipseInRect(context, CGRectMake(100, 100, 100, 200));

//    //椭圆边框

//    CGContextStrokeEllipseInRect(context, CGRectMake(100, 100, 100, 200));

//    //设置填充色

//    [[UIColor orangeColor] set];

//    //绘图并直接填充颜色

//    CGContextFillEllipseInRect(context, CGRectMake(100, 100, 100, 200));

//    //矩形/正方形

//    CGContextAddRect(context, CGRectMake(100, 100, 200, 100));

//    //文字

//    NSString *string = @"文字";

//   [string drawInRect:CGRectMake(100, 100, 100, 100) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:40],NSForegroundColorAttributeName:[UIColor greenColor]}];

//    CGContextAddArc(context, 200, 200, 100, 0, M_PI*2, 1);

//    [[UIColor orangeColor] set];

//    CGContextFillPath(context);

//    [string drawAtPoint:CGPointMake(180, 180) withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:40],NSForegroundColorAttributeName:[UIColor greenColor]}];

//绘制图片

UIImage*image = [UIImageimageNamed:@"8.jpg"];

[imagedrawInRect:CGRectMake(20, 100, 200, 200)];

//绘图

CGContextStrokePath(context);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容