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

来源:互联网 发布:熊猫安卓手游直播软件 编辑:程序博客网 时间:2024/05/21 19:39

前提: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();  }  

0 0