leaves
leaves copied to clipboard
Can I just load another UIView without using core graphics to render next page?
In the examples project, every page is rendered using core graphics. I have a UIView want to displaying in the next page, it's a grid view layout page. How to make it to show at the next page in the - (void)renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx method?
I needed to do just that too, so I went ahead and created an example of how to render a page from UIView. I will create a pull request for the added example in the XCode project.
- (void) renderPageAtIndex:(NSUInteger)index inContext:(CGContextRef)ctx {
CGRect bounds = CGContextGetClipBoundingBox(ctx);
UIView* renderView = [[[UIView alloc] initWithFrame:bounds] autorelease];
renderView.backgroundColor = [UIColor colorWithHue:index/10.0
saturation:0.8
brightness:0.8
alpha:1.0];
UILabel* label = [[[UILabel alloc] initWithFrame:bounds] autorelease];
label.text = [NSString stringWithFormat:@"Page number %d", index];
label.textAlignment = UITextAlignmentCenter;
[renderView addSubview:label];
// View will render upside down if we omit this:
CGAffineTransform verticalFlip = CGAffineTransformMake(1, 0, 0, -1, 0, bounds.size.height);
CGContextConcatCTM(ctx, verticalFlip);
// We call renderInContext on the layer to draw the view onto the context
[renderView.layer renderInContext:ctx];
}