Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example for rendering page from UIView #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions LeavesExamples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
1DF5F4E00D08C38300B7A737 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; };
288765A50DF7441C002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765A40DF7441C002DB57D /* CoreGraphics.framework */; };
7D35172818913B0A00AF1404 /* UIViewExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D35172718913B0A00AF1404 /* UIViewExampleViewController.m */; };
D337E308119B61A5003E5728 /* LeavesCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D337E307119B61A5003E5728 /* LeavesCache.m */; };
D33D45A2117BDE0100BA7203 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D33D45A1117BDE0100BA7203 /* QuartzCore.framework */; };
D33D4E5B117D818100BA7203 /* LeavesView.m in Sources */ = {isa = PBXBuildFile; fileRef = D33D4E58117D818100BA7203 /* LeavesView.m */; };
Expand All @@ -35,6 +36,8 @@
1D6058910D05DD3D006BFB54 /* LeavesExamples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LeavesExamples.app; sourceTree = BUILT_PRODUCTS_DIR; };
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
288765A40DF7441C002DB57D /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
7D35172618913B0A00AF1404 /* UIViewExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIViewExampleViewController.h; sourceTree = "<group>"; };
7D35172718913B0A00AF1404 /* UIViewExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIViewExampleViewController.m; sourceTree = "<group>"; };
D337E306119B61A5003E5728 /* LeavesCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LeavesCache.h; sourceTree = "<group>"; };
D337E307119B61A5003E5728 /* LeavesCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LeavesCache.m; sourceTree = "<group>"; };
D33D45A1117BDE0100BA7203 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -139,6 +142,8 @@
EA97677917EB8E3C001A0F1C /* PDFExampleViewController.m */,
EA97677A17EB8E3C001A0F1C /* ProceduralExampleViewController.h */,
EA97677B17EB8E3C001A0F1C /* ProceduralExampleViewController.m */,
7D35172618913B0A00AF1404 /* UIViewExampleViewController.h */,
7D35172718913B0A00AF1404 /* UIViewExampleViewController.m */,
);
name = Classes;
path = LeavesExamples/Classes;
Expand Down Expand Up @@ -240,6 +245,7 @@
buildActionMask = 2147483647;
files = (
EA97678E17EB8E3C001A0F1C /* ProceduralExampleViewController.m in Sources */,
7D35172818913B0A00AF1404 /* UIViewExampleViewController.m in Sources */,
D33D4E5B117D818100BA7203 /* LeavesView.m in Sources */,
EA97678A17EB8E3C001A0F1C /* ExamplesViewController.m in Sources */,
EA97678D17EB8E3C001A0F1C /* PDFExampleViewController.m in Sources */,
Expand Down
7 changes: 6 additions & 1 deletion LeavesExamples/Classes/ExamplesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#import "PDFExampleViewController.h"
#import "ImageExampleViewController.h"
#import "ProceduralExampleViewController.h"
#import "UIViewExampleViewController.h"

enum {ExamplePDF, ExampleImage, ExampleProcedural, NumExamples};
enum {ExamplePDF, ExampleImage, ExampleProcedural, ExampleUIView, NumExamples};

@implementation ExamplesViewController

Expand Down Expand Up @@ -45,6 +46,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
case ExamplePDF: cell.textLabel.text = @"PDF example"; break;
case ExampleImage: cell.textLabel.text = @"Image example"; break;
case ExampleProcedural: cell.textLabel.text = @"Procedural example"; break;
case ExampleUIView: cell.textLabel.text = @"UIView example"; break;
default: cell.textLabel.text = @"";
}
return cell;
Expand All @@ -64,6 +66,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
case ExampleProcedural:
viewController = [[[ProceduralExampleViewController alloc] init] autorelease];
break;
case ExampleUIView:
viewController = [[[UIViewExampleViewController alloc] init] autorelease];
break;
default:
viewController = nil;
}
Expand Down
13 changes: 13 additions & 0 deletions LeavesExamples/Classes/UIViewExampleViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// UIViewExampleViewController.h
// LeavesExamples
//
// Created by Aemotion on 23-01-14.
// Copyright (c) 2014 Tom Brow. All rights reserved.
//

#import "LeavesViewController.h"

@interface UIViewExampleViewController : LeavesViewController

@end
45 changes: 45 additions & 0 deletions LeavesExamples/Classes/UIViewExampleViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// UIViewExampleViewController.m
// LeavesExamples
//
// Created by Aemotion on 23-01-14.
// Copyright (c) 2014 Tom Brow. All rights reserved.
//

#import "UIViewExampleViewController.h"

@implementation UIViewExampleViewController

#pragma mark LeavesViewDataSource

- (NSUInteger)numberOfPagesInLeavesView:(LeavesView*)leavesView {
return 10;
}

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


@end