1.绘制饼状图
a.获取上下文
CGContextRef context=UIGraphicsGetCurrentContext( );
b.绘制一段圆弧
CGContextAddArc(context , x,y,M_PI*a,M_PI*b,0);
c.绘制一条直线
CGContextAddLineToPoint( context,x,y);
d.设置闭合
CGContextClosePath(context);
e.设置线条颜色和填充色
[ [ UIColor redColor] set];
[ [ UIColor redColor] setFill];
f.渲染线条和填充色
CGContextStrokePath(context);
2.绘制曲线
a.获取上下文
CGContextRef context=UIGraphicsGetCurrentContext( );
b.设置曲线的起点
CGContextMoveToPoint(context,x,y);
c.绘制曲线
CGContextAddCurveToPoint(context,点1的x坐标,点1的y坐标,点2的x坐标,点2的y坐标,曲线的终点x坐标,终点的y坐标);
d.设置颜色
[ [ UIColor redColor ] set ];
e.渲染颜色
CGContextStrokePath( context);
3.裁剪图片
a.获取背景图
UIImage *image=[ UIImage imageNamed:图片的名字];
b.开始
UIGraphicsBeginImageContext( image.size);
c.获取山下文
CGContextRef context=UIGraphicsGetCurrentContext( );
d.
CGContextAddEllipseInRect(context, CGRect (0,0,image.size.width, image.size.height ) );
e.裁剪
CGContextClip( context );
f.
[ image drawAtPoint:CGPointZero];
g.获取裁剪后的新图片
UIImage * newImage=UIGraphicsGetImageFromCurrentImageContext( );
h.设置一个UIImageView
UIImageView *imageView=[ [ UIImageView alloc] initWithFrame:CGRectMake(0,20,image.size.width,image.size.height) ];
i.设置imageView所要显示的内容
imageView. image=newImage;
j.添加到根视图上
[ self.view addSubView: imageView];
l.结束
UIGraphicsEndImageContext( );
4.添加水印
a.获得背景图
UIImage *backImage=[ UIImage imageNamed:背景图片];
b.开始
UIGraphicsBeginImageContextWithOptions(backImage.size,动画效果,缩放比例 );
c.
[ backImage drawInRect:CGRectMake(0,0,backImage.size.width,backImage.size.height)];
d.获得水印图片
UIImage * waterImage=[ UIImage imageNamed:水印图片];
e.
[ waterImage drawInRect : CGRectMake( backImage.size.width-waterImage.size.width*0.1-100,backImage.size.height-waterImage.size.height*0.1-100,waterImage.size.width*0.2,waterImage.size.height*0.2 ) blendMode:kCGBlendModeNormal alpha:0.5];
f.获取新的图片
UIImage *newImage= UIGraphicsGetImageFromCurrentImageContext( );
g.绘制UIImageView
UIImageView *imageView=[ [ UIImageView alloc] initWithFrame:CGRectMake( 0,20,self.frame.size.width,self.frame.size.height-20)] ;
imageView.image=newImage;
[ self addSubView:imageView];