UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
2. 在baseView上加上blueView和yellowView
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
blueView.backgroundColor = [UIColor blueColor];
[baseView addSubview:blueView];
UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(100, 0, 100, 100)];
yellowView.backgroundColor = [UIColor yellowColor];
[baseView addSubview:yellowView];
UIGraphicsBeginImageContext(baseView.bounds.size);
[baseView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *imageView = [[UIImageView alloc]
initWithFrame:CGRectMake(20, 20, 200, 100)];
imageView.image = image ;
[self.view addSubview:imageView];

Email me when 彼得潘的App Neverland publishes or recommends stories