leaves icon indicating copy to clipboard operation
leaves copied to clipboard

Can I just load another UIView without using core graphics to render next page?

Open y0unghe opened this issue 11 years ago • 1 comments

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?

y0unghe avatar Jan 17 '14 13:01 y0unghe

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];
}

Hless avatar Jan 23 '14 12:01 Hless