不说废话,直接上代码
//显示数据
-(void)fun_show_data
{
UIGraphicsBeginImageContext(_img_show_data.frame.size);
CGContextRef ref = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ref, 5);
CGContextSetAllowsAntialiasing(ref, YES);
CGContextSetRGBStrokeColor(ref, 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(ref);
CGContextMoveToPoint(ref, 0, img_rect.size.height/2);
CGContextAddLineToPoint(ref, img_rect.size.width, img_rect.size.height/2);
CGContextStrokePath(ref);
NSString *str = @"你好!";
[str drawInRect:CGRectMake(50, 50, 100, 100) withAttributes:nil];
CGContextStrokeRect(ref, CGRectMake(0, 0, img_rect.size.width, img_rect.size.height));
_img_show_data.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}

本文介绍了一个iOS应用中使用Core Graphics进行简单绘图的方法。通过具体的代码实现,展示了如何绘制一条红线,并在视图中显示中文文字及边框。此教程适合初学者了解iOS图形绘制的基础操作。
1224

被折叠的 条评论
为什么被折叠?



