UIBezierPath到UIImage

我需要画一张饼图。 我在这里find了一个很好的教程http://mac-objective-c.blogspot.com/2009/04/drawing-pie-charts.html

该示例使用NSBezierPath,但我使用UIBezierPath,因为我需要IOS中的graphics。

有没有办法在UIImage中获得graphics,所以我可以在UIImageView中显示它?

在这个教程http://blog.gafmediastudio.com/2010/07/02/draw-a-pie-chart-with-iphone-ipod-ipad/他们使用CGContext,最后他们有一个函数返回一个UIImage 。

UIBezierPath类似乎更容易使用,所以我怎么能得到在UIImage中的绘图? 从我读的改变drawRect不是很推荐。 至less,不是为了我想要做的。

谢谢!

首先拍摄你的屏幕的照片,并裁剪所需大小的图像。

UIGraphicsBeginImageContext(self.view.frame.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage* img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); //Crop the image CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], CGRectMake(0, 44, 1024, 660)); img = [UIImage imageWithCGImage:imageRef];