上一个是绘制简单图形,这一篇学习绘制文字、图像
//获取画布 CGContextRef context=UIGraphicsGetCurrentContext(); //设置边框颜色 CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); //文字绘制 两种绘制方法 NSString *[email protected]"我是崔彦威"; NSDictionary *[email protected]{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor redColor]}; [text drawInRect:CGRectMake(0, 0, 200, 20) withAttributes:dic]; [text drawAtPoint:CGPointMake(200, 0) withAttributes:dic]; //图片绘制 UIImage *img=[UIImage imageNamed:@"img.jpg"]; //在矩形中绘制 // [img drawInRect:CGRectMake(20, 20, 120, 120)]; //以点开始绘制 // [img drawAtPoint:CGPointMake(20, 20)]; //平铺绘图 [img drawAsPatternInRect:CGRectMake(20, 20, 240, 300)];
时间: 2024-12-14 11:35:38