首页 > 其他 > 详细

在imageView上画线(转)

时间:2016-11-01 13:36:49      阅读:278      评论:0      收藏:0      [点我收藏+]

前提:CoreGraphics.framework

- (void)viewDidLoad {  
    [super viewDidLoad];  
   
    UIImageView *imageView=[[UIImageView alloc] initWithFrame:self.view.frame];  
    [self.view addSubview:imageView];  
   
    self.view.backgroundColor=[UIColor blueColor];  
   
    UIGraphicsBeginImageContext(imageView.frame.size);  
    [imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];  
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15.0);  //线宽
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);  
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);  //颜色另有UIColor转为RGB方法见博客  
    CGContextBeginPath(UIGraphicsGetCurrentContext());  
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 100, 100);  //起点坐标
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 200, 100);   //终点坐标
    CGContextStrokePath(UIGraphicsGetCurrentContext());  
    imageView.image=UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();  
}  

在imageView上画线(转)

原文:http://www.cnblogs.com/sunmair/p/6018914.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!