//开始绘画
UIGraphicsBeginImageContext(self.view.bounds.size);
CGContextRef gc = UIGraphicsGetCurrentContext();
//设置颜色
[[UIColor grayColor] setFill];
//设置中心点
CGFloat cenX = CGRectGetMidX(self.view.bounds);
CGFloat cenY = CGRectGetMidY(self.view.bounds);
CGContextTranslateCTM(gc, cenX, cenY);
//不断绘图并设置旋转
for (int i = 0; i < 12; i ++) {
// CGContextAddRect(gc, CGRectMake(-5, 0, 10, 100));
CGContextAddRect(gc, CGRectMake(-5, 50, 10, 50));
// CGContextAddRect(gc, CGRectMake(-5, 10, 2, 50));
CGContextFillPath(gc);
CGContextRotateCTM(gc, 30 * M_PI / 180);
}
//结束绘画
UIImage *destImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//创建UIImageView并显示在界面上
UIImageView *imageView = [[UIImageView alloc] initWithImage:destImg];
[self.view addSubview:imageView];
网友评论