1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| -(void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; UIGraphicsBeginImageContext(self.view.bounds.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGRect currentRect = self.view.frame; CGContextAddRect(context, currentRect); CGContextDrawPath(context, kCGPathFillStroke); CGRect original = CGRectMake(100, 100, 200, 200); CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); CGContextAddRect(context, original); CGContextDrawPath(context, kCGPathFillStroke); CGRect firstRect = CGRectInset(original, 10, 10); CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor); CGContextAddRect(context, firstRect); CGContextDrawPath(context, kCGPathFillStroke); CGRect secondRect = CGRectInset(firstRect, 10, 10); CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor); CGContextAddRect(context, secondRect); CGContextDrawPath(context, kCGPathFillStroke); CGRect thirdRect = CGRectInset(secondRect, 10, 10); CGContextSetFillColorWithColor(context, [UIColor yellowColor].CGColor); CGContextAddRect(context, thirdRect); CGContextDrawPath(context, kCGPathFillStroke); CGRect fourRect = CGRectInset(thirdRect, 10, 10); CGContextSetFillColorWithColor(context, [UIColor grayColor].CGColor); CGContextAddRect(context, fourRect); UIImage *destImg = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageView *imgView = [[UIImageView alloc] initWithImage:destImg]; [self.view addSubview:imgView]; }
|