iOS-实现最简单的画线功能 . 转


前提: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);  //颜色  
    CGContextBeginPath(UIGraphicsGetCurrentContext());  
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 100, 100);  //起点坐标
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 200, 100);   //终点坐标
    CGContextStrokePath(UIGraphicsGetCurrentContext());  
    imageView.image=UIGraphicsGetImageFromCurrentImageContext();  
    UIGraphicsEndImageContext();  
}  

 

此处的RGB 用的时小数来表示,如灰色(0.8,0.8,0.8)

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.8, 0.8, 0.8, 1.0);

 

http://marshal.easymorse.com/archives/4046


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM