- (void)viewDidLoad
{
[super viewDidLoad];
for (int i=0; i<200; i++) {
//产生随机数
int a = arc4random()%80;
UIGraphicsBeginImageContext(CGSizeMake(a, a));//设置上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextBeginPath(ctx);
CGContextAddArc(ctx, a/2, a/2, a/2, 0, 2*M_PI, 0);
CGContextSetRGBFillColor(ctx, rand()/(RAND_MAX+1.0),rand()/(RAND_MAX+1.0),rand()/(RAND_MAX+1.0),rand()/(RAND_MAX+1.0));//随机颜色
CGContextFillPath(ctx);
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(arc4random()%320, arc4random()%460, a, a)];
view.image = image;
[self.view addSubview:view];
}
}