从core graphics获取UIImage的方法:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- (void)viewDidLoad
{
    [super viewDidLoad];

    UIGraphicsBeginImageContext(CGSizeMake(20,20));
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextBeginPath(ctx);
    CGContextAddArc(ctx, 10, 10, 10, 0, 2*M_PI, 1);
    CGContextSetRGBFillColor(ctx, 1,0, 0, 1);
    CGContextFillPath(ctx);
    UIImage *redBall = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageView *redBallView = [[UIImageView alloc] initWithImage:redBall];
    redBallView.center = CGPointMake(160,330);
    [self.view addSubview:redBallView];
}