Skip to content

Commit 91cebab

Browse files
author
Andreas Zeitler
committed
add: expose members to make viewer stylable and localizable
1 parent 597cf55 commit 91cebab

File tree

4 files changed

+103
-61
lines changed

4 files changed

+103
-61
lines changed

Classes/View/PDFKBasicPDFViewer.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#import <UIKit/UIKit.h>
1717
@class PDFKDocument;
18+
@class PDFKPageScrubber;
19+
@class PDFKBasicPDFViewerSinglePageCollectionView;
20+
@class PDFKBasicPDFViewerThumbsCollectionView;
1821

1922
typedef void (^PDFKBasicPDFViewerPageChangeBlock)(NSUInteger page);
2023

@@ -81,5 +84,54 @@ typedef void (^PDFKBasicPDFViewerPageChangeBlock)(NSUInteger page);
8184
*/
8285
@property (nonatomic, assign) BOOL standalone;
8386

87+
/**
88+
The toolbar displaied at the top of the screen.
89+
*/
90+
@property (nonatomic, retain, readonly) UIToolbar *navigationToolbar;
91+
/**
92+
The slider at the bottom of the screen to show the thumbnails.
93+
*/
94+
@property (nonatomic, retain, readonly) UIToolbar *thumbnailSlider;
95+
/**
96+
The popover controller to share the document on the iPad.
97+
*/
98+
@property (nonatomic, strong, readonly) UIPopoverController *activityPopoverController;
99+
/**
100+
The share button.
101+
*/
102+
@property (nonatomic, strong, readonly) UIBarButtonItem *shareItem;
103+
/**
104+
The item that notes wether or not the page is bookmarked.
105+
*/
106+
@property (nonatomic, strong, readonly) UIBarButtonItem *bookmarkItem;
107+
/**
108+
The page scrubber at the bottom of the view.
109+
*/
110+
@property (nonatomic, strong, readonly) PDFKPageScrubber *pageScrubber;
111+
/**
112+
The collection view of single pages to display.
113+
*/
114+
@property (nonatomic, strong, readonly) PDFKBasicPDFViewerSinglePageCollectionView *pageCollectionView;
115+
/**
116+
Wether or not the view is showing a single page.
117+
*/
118+
@property (nonatomic, assign, readonly) BOOL showingSinglePage;
119+
/**
120+
The collection view that displays all the thumbs.
121+
*/
122+
@property (nonatomic, strong, readonly) PDFKBasicPDFViewerThumbsCollectionView *thumbsCollectionView;
123+
/**
124+
Wether or not the thumbs collection view is showing thumbs.
125+
*/
126+
@property (nonatomic, assign, readonly) BOOL showingBookmarks;
127+
/**
128+
YES once view did load called.
129+
*/
130+
@property (nonatomic, assign, readonly) BOOL loadedView;
131+
132+
/**
133+
title of the button for going back from thumbnail-view to page-view
134+
*/
135+
@property (nonatomic, strong) NSString *backButtonTitle;
84136

85137
@end

Classes/View/PDFKBasicPDFViewer.m

Lines changed: 26 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,58 +21,27 @@
2121
#import "PDFKBasicPDFViewerSinglePageCollectionView.h"
2222
#import <TTOpenInAppActivity/TTOpenInAppActivity.h>
2323

24+
2425
@interface PDFKBasicPDFViewer () <UIToolbarDelegate, UIDocumentInteractionControllerDelegate, PDFKPageScrubberDelegate, UIGestureRecognizerDelegate, PDFKBasicPDFViewerThumbsCollectionViewDelegate, PDFKBasicPDFViewerSinglePageCollectionViewDelegate>
2526

26-
/**
27-
The toolbar displaied at the top of the screen.
28-
*/
29-
@property (nonatomic, retain) UIToolbar *navigationToolbar;
30-
/**
31-
The slider at the bottom of the screen to show the thumbnails.
32-
*/
33-
@property (nonatomic, retain) UIToolbar *thumbnailSlider;
34-
/**
35-
The popover controller to share the document on the iPad.
36-
*/
37-
@property (nonatomic, strong) UIPopoverController *activityPopoverController;
38-
/**
39-
The share button.
40-
*/
41-
@property (nonatomic, strong) UIBarButtonItem *shareItem;
42-
/**
43-
The item that notes wether or not the page is bookmarked.
44-
*/
45-
@property (nonatomic, strong) UIBarButtonItem *bookmarkItem;
46-
/**
47-
The page scrubber at the bottom of the view.
48-
*/
49-
@property (nonatomic, strong) PDFKPageScrubber *pageScrubber;
50-
/**
51-
The collection view of single pages to display.
52-
*/
53-
@property (nonatomic, strong) PDFKBasicPDFViewerSinglePageCollectionView *pageCollectionView;
54-
/**
55-
Wether or not the view is showing a single page.
56-
*/
57-
@property (nonatomic, assign) BOOL showingSinglePage;
58-
/**
59-
The collection view that displays all the thumbs.
60-
*/
61-
@property (nonatomic, strong) PDFKBasicPDFViewerThumbsCollectionView *thumbsCollectionView;
62-
/**
63-
Wether or not the thumbs collection view is showing thumbs.
64-
*/
65-
@property (nonatomic, assign) BOOL showingBookmarks;
66-
/**
67-
YES once view did load called.
68-
*/
69-
@property (nonatomic, assign) BOOL loadedView;
27+
@property (nonatomic, retain, readwrite) UIToolbar *navigationToolbar;
28+
@property (nonatomic, retain, readwrite) UIToolbar *thumbnailSlider;
29+
@property (nonatomic, strong, readwrite) UIPopoverController *activityPopoverController;
30+
@property (nonatomic, strong, readwrite) UIBarButtonItem *shareItem;
31+
@property (nonatomic, strong, readwrite) UIBarButtonItem *bookmarkItem;
32+
@property (nonatomic, strong, readwrite) PDFKPageScrubber *pageScrubber;
33+
@property (nonatomic, strong, readwrite) PDFKBasicPDFViewerSinglePageCollectionView *pageCollectionView;
34+
@property (nonatomic, assign, readwrite) BOOL showingSinglePage;
35+
@property (nonatomic, strong, readwrite) PDFKBasicPDFViewerThumbsCollectionView *thumbsCollectionView;
36+
@property (nonatomic, assign, readwrite) BOOL showingBookmarks;
37+
@property (nonatomic, assign, readwrite) BOOL loadedView;
7038

7139
@property (nonatomic, strong) UITapGestureRecognizer *singleTapGestureRecognizer;
7240
@property (nonatomic, strong) UITapGestureRecognizer *doubleTapGestureRecognizer;
7341

7442
@end
7543

44+
7645
@implementation PDFKBasicPDFViewer
7746

7847
#pragma mark - Initalization and Loading
@@ -290,15 +259,6 @@ - (void)resetNavigationToolbar
290259
UIBarButtonItem *listItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Thumbs"] landscapeImagePhone:[UIImage imageNamed:@"Thumbs"] style:UIBarButtonItemStylePlain target:self action:@selector(list)];
291260
[buttonsArray addObject:listItem];
292261

293-
//Sharing Button
294-
if (_enableSharing || _enablePrinting || _enableOpening) {
295-
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
296-
space.width = 10.0;
297-
[buttonsArray addObject:space];
298-
_shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(send)];
299-
[buttonsArray addObject:_shareItem];
300-
}
301-
302262
//Flexible space
303263
[buttonsArray addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]];
304264

@@ -318,6 +278,15 @@ - (void)resetNavigationToolbar
318278

319279
[buttonsArray addObject:_bookmarkItem];
320280
}
281+
282+
//Sharing Button
283+
if (_enableSharing || _enablePrinting || _enableOpening) {
284+
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
285+
space.width = 10.0;
286+
[buttonsArray addObject:space];
287+
_shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(send)];
288+
[buttonsArray addObject:_shareItem];
289+
}
321290
} else {
322291

323292
//Set controls for thumbs
@@ -335,7 +304,10 @@ - (void)resetNavigationToolbar
335304
}
336305

337306
//Go back
338-
UIBarButtonItem *listItem = [[UIBarButtonItem alloc] initWithTitle:@"Resume" style:UIBarButtonItemStylePlain target:self action:@selector(list)];
307+
if (!self.backButtonTitle) {
308+
self.backButtonTitle = @"Resume";
309+
}
310+
UIBarButtonItem *listItem = [[UIBarButtonItem alloc] initWithTitle:self.backButtonTitle style:UIBarButtonItemStylePlain target:self action:@selector(list)];
339311
[buttonsArray addObject:listItem];
340312

341313
//Flexible space

Classes/View/PDFKPageScrubber.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@
5757
*/
5858
@property (nonatomic, weak, readwrite) id <PDFKPageScrubberDelegate> scrubberDelegate;
5959

60+
/**
61+
The scrubber's page number label – use for styling.
62+
*/
63+
@property (nonatomic, strong) UILabel *pageNumberLabel;
64+
65+
/**
66+
the background color of the thumb
67+
defaults to [UIColor colorWithWhite:0.8 ...]
68+
*/
69+
@property (nonatomic, strong) UIColor *thumbBackgroundColor;
70+
6071
/**
6172
Initalize the scrubber with the given frame and document.
6273
@@ -98,6 +109,6 @@
98109
99110
@return A new thumb view.
100111
*/
101-
- (id)initWithFrame:(CGRect)frame small:(BOOL)small;
112+
- (id)initWithFrame:(CGRect)frame small:(BOOL)small andColor:(UIColor *)color;
102113

103114
@end

Classes/View/PDFKPageScrubber.m

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ @implementation PDFKPageScrubber
6565
NSTimer *trackTimer;
6666
}
6767

68+
@synthesize pageNumberLabel = pageNumberLabel;
69+
6870
- (id)initWithFrame:(CGRect)frame
6971
{
7072
return [self initWithFrame:frame document:nil];
@@ -144,6 +146,12 @@ - (id)initWithFrame:(CGRect)frame document:(PDFKDocument *)object
144146
return self;
145147
}
146148

149+
- (UIColor *)thumbBackgroundColor {
150+
if (!_thumbBackgroundColor) {
151+
return [UIColor colorWithWhite:0.8 alpha:1];
152+
}
153+
return _thumbBackgroundColor;
154+
}
147155

148156
- (void)removeFromSuperview
149157
{
@@ -241,7 +249,7 @@ - (void)layoutSubviews
241249
CGRect thumbRect = CGRectMake(thumbX, thumbY, THUMB_LARGE_WIDTH, THUMB_LARGE_HEIGHT);
242250

243251
//Create the thumb view
244-
pageThumbView = [[PDFKPageScrubberThumb alloc] initWithFrame:thumbRect];
252+
pageThumbView = [[PDFKPageScrubberThumb alloc] initWithFrame:thumbRect small:NO andColor:self.thumbBackgroundColor];
245253
//Z position so that it sits on top of the small thumbs
246254
pageThumbView.layer.zPosition = 1.0f;
247255
//Add as the first subview of the track control
@@ -289,7 +297,7 @@ - (void)layoutSubviews
289297
NSString *phrase = document.password;
290298

291299
//Create a small thumb view
292-
smallThumbView = [[PDFKPageScrubberThumb alloc] initWithFrame:thumbRect small:YES];
300+
smallThumbView = [[PDFKPageScrubberThumb alloc] initWithFrame:thumbRect small:YES andColor:self.thumbBackgroundColor];
293301
PDFKThumbRequest *thumbRequest = [PDFKThumbRequest newForView:smallThumbView fileURL:fileURL password:phrase guid:guid page:page size:size];
294302

295303
//Request the thumb
@@ -525,16 +533,15 @@ @implementation PDFKPageScrubberThumb
525533

526534
- (id)initWithFrame:(CGRect)frame
527535
{
528-
return [self initWithFrame:frame small:NO];
536+
return [self initWithFrame:frame small:NO andColor:[UIColor colorWithWhite:0.8 alpha:0]];
529537
}
530538

531-
- (id)initWithFrame:(CGRect)frame small:(BOOL)small
539+
- (id)initWithFrame:(CGRect)frame small:(BOOL)small andColor:(UIColor *)color
532540
{
533541
if ((self = [super initWithFrame:frame]))
534542
{
535543
CGFloat value = (small ? 0.6f : 0.7f); // Size based alpha value
536-
537-
UIColor *background = [UIColor colorWithWhite:0.8f alpha:value];
544+
UIColor *background = [color colorWithAlphaComponent:value];
538545

539546
self.backgroundColor = background;
540547
imageView.backgroundColor = background;

0 commit comments

Comments
 (0)