IOS CGContextRef 写图形跟文字

来源:互联网 发布:重庆网络推广 编辑:程序博客网 时间:2024/06/03 20:23

不说废话,直接上代码
//显示数据
-(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();

}

0 0
原创粉丝点击