ReaderMainPagebar.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. //
  2. // ReaderMainPagebar.m
  3. // Reader v2.8.6
  4. //
  5. // Created by Julius Oklamcak on 2011-09-01.
  6. // Copyright © 2011-2015 Julius Oklamcak. All rights reserved.
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights to
  11. // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  12. // of the Software, and to permit persons to whom the Software is furnished to
  13. // do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in all
  16. // copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  22. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  23. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. //
  25. #import "ReaderConstants.h"
  26. #import "ReaderMainPagebar.h"
  27. #import "ReaderThumbCache.h"
  28. #import "ReaderDocument.h"
  29. #import <QuartzCore/QuartzCore.h>
  30. @implementation ReaderMainPagebar
  31. {
  32. ReaderDocument *document;
  33. ReaderTrackControl *trackControl;
  34. NSMutableDictionary *miniThumbViews;
  35. ReaderPagebarThumb *pageThumbView;
  36. UILabel *pageNumberLabel;
  37. UIView *pageNumberView;
  38. NSTimer *enableTimer;
  39. NSTimer *trackTimer;
  40. }
  41. #pragma mark - Constants
  42. #define THUMB_SMALL_GAP 2
  43. #define THUMB_SMALL_WIDTH 22
  44. #define THUMB_SMALL_HEIGHT 28
  45. #define THUMB_LARGE_WIDTH 32
  46. #define THUMB_LARGE_HEIGHT 42
  47. #define PAGE_NUMBER_WIDTH 96.0f
  48. #define PAGE_NUMBER_HEIGHT 30.0f
  49. #define PAGE_NUMBER_SPACE_SMALL 16.0f
  50. #define PAGE_NUMBER_SPACE_LARGE 32.0f
  51. #define SHADOW_HEIGHT 4.0f
  52. #pragma mark - Properties
  53. @synthesize delegate;
  54. #pragma mark - ReaderMainPagebar class methods
  55. + (Class)layerClass
  56. {
  57. #if (READER_FLAT_UI == FALSE) // Option
  58. return [CAGradientLayer class];
  59. #else
  60. return [CALayer class];
  61. #endif // end of READER_FLAT_UI Option
  62. }
  63. #pragma mark - ReaderMainPagebar instance methods
  64. - (instancetype)initWithFrame:(CGRect)frame
  65. {
  66. return [self initWithFrame:frame document:nil];
  67. }
  68. - (void)updatePageThumbView:(NSInteger)page
  69. {
  70. NSInteger pages = [document.pageCount integerValue];
  71. if (pages > 1) // Only update frame if more than one page
  72. {
  73. CGFloat controlWidth = trackControl.bounds.size.width;
  74. CGFloat useableWidth = (controlWidth - THUMB_LARGE_WIDTH);
  75. CGFloat stride = (useableWidth / (pages - 1)); // Page stride
  76. NSInteger X = (stride * (page - 1)); CGFloat pageThumbX = X;
  77. CGRect pageThumbRect = pageThumbView.frame; // Current frame
  78. if (pageThumbX != pageThumbRect.origin.x) // Only if different
  79. {
  80. pageThumbRect.origin.x = pageThumbX; // The new X position
  81. pageThumbView.frame = pageThumbRect; // Update the frame
  82. }
  83. }
  84. if (page != pageThumbView.tag) // Only if page number changed
  85. {
  86. pageThumbView.tag = page; [pageThumbView reuse]; // Reuse the thumb view
  87. CGSize size = CGSizeMake(THUMB_LARGE_WIDTH, THUMB_LARGE_HEIGHT); // Maximum thumb size
  88. NSURL *fileURL = document.fileURL; NSString *guid = document.guid; NSString *phrase = document.password;
  89. ReaderThumbRequest *request = [ReaderThumbRequest newForView:pageThumbView fileURL:fileURL password:phrase guid:guid page:page size:size];
  90. UIImage *image = [[ReaderThumbCache sharedInstance] thumbRequest:request priority:YES]; // Request the thumb
  91. UIImage *thumb = ([image isKindOfClass:[UIImage class]] ? image : nil); [pageThumbView showImage:thumb];
  92. }
  93. }
  94. - (void)updatePageNumberText:(NSInteger)page
  95. {
  96. if (page != pageNumberLabel.tag) // Only if page number changed
  97. {
  98. NSInteger pages = [document.pageCount integerValue]; // Total pages
  99. NSString *format = NSLocalizedString(@"%i of %i", @"format"); // Format
  100. NSString *number = [[NSString alloc] initWithFormat:format, (int)page, (int)pages];
  101. pageNumberLabel.text = number; // Update the page number label text
  102. pageNumberLabel.tag = page; // Update the last page number tag
  103. }
  104. }
  105. - (instancetype)initWithFrame:(CGRect)frame document:(ReaderDocument *)object
  106. {
  107. assert(object != nil); // Must have a valid ReaderDocument
  108. if ((self = [super initWithFrame:frame]))
  109. {
  110. self.autoresizesSubviews = YES;
  111. self.userInteractionEnabled = YES;
  112. self.contentMode = UIViewContentModeRedraw;
  113. self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
  114. if ([self.layer isKindOfClass:[CAGradientLayer class]])
  115. {
  116. self.backgroundColor = [UIColor clearColor];
  117. CAGradientLayer *layer = (CAGradientLayer *)self.layer;
  118. UIColor *liteColor = [UIColor colorWithWhite:0.82f alpha:0.8f];
  119. UIColor *darkColor = [UIColor colorWithWhite:0.32f alpha:0.8f];
  120. layer.colors = [NSArray arrayWithObjects:(id)liteColor.CGColor, (id)darkColor.CGColor, nil];
  121. CGRect shadowRect = self.bounds; shadowRect.size.height = SHADOW_HEIGHT; shadowRect.origin.y -= shadowRect.size.height;
  122. ReaderPagebarShadow *shadowView = [[ReaderPagebarShadow alloc] initWithFrame:shadowRect];
  123. [self addSubview:shadowView]; // Add shadow to toolbar
  124. }
  125. else // Follow The Fuglyosity of Flat Fad
  126. {
  127. self.backgroundColor = [UIColor colorWithWhite:0.94f alpha:0.94f];
  128. CGRect lineRect = self.bounds; lineRect.size.height = 1.0f; lineRect.origin.y -= lineRect.size.height;
  129. UIView *lineView = [[UIView alloc] initWithFrame:lineRect];
  130. lineView.autoresizesSubviews = NO;
  131. lineView.userInteractionEnabled = NO;
  132. lineView.contentMode = UIViewContentModeRedraw;
  133. lineView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  134. lineView.backgroundColor = [UIColor colorWithWhite:0.64f alpha:0.94f];
  135. [self addSubview:lineView];
  136. }
  137. CGFloat space = (([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) ? PAGE_NUMBER_SPACE_LARGE : PAGE_NUMBER_SPACE_SMALL);
  138. CGFloat numberY = (0.0f - (PAGE_NUMBER_HEIGHT + space)); CGFloat numberX = ((self.bounds.size.width - PAGE_NUMBER_WIDTH) * 0.5f);
  139. CGRect numberRect = CGRectMake(numberX, numberY, PAGE_NUMBER_WIDTH, PAGE_NUMBER_HEIGHT);
  140. pageNumberView = [[UIView alloc] initWithFrame:numberRect]; // Page numbers view
  141. pageNumberView.autoresizesSubviews = NO;
  142. pageNumberView.userInteractionEnabled = NO;
  143. pageNumberView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
  144. pageNumberView.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.4f];
  145. pageNumberView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
  146. pageNumberView.layer.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.6f].CGColor;
  147. pageNumberView.layer.shadowPath = [UIBezierPath bezierPathWithRect:pageNumberView.bounds].CGPath;
  148. pageNumberView.layer.shadowRadius = 2.0f; pageNumberView.layer.shadowOpacity = 1.0f;
  149. CGRect textRect = CGRectInset(pageNumberView.bounds, 4.0f, 2.0f); // Inset the text a bit
  150. pageNumberLabel = [[UILabel alloc] initWithFrame:textRect]; // Page numbers label
  151. pageNumberLabel.autoresizesSubviews = NO;
  152. pageNumberLabel.autoresizingMask = UIViewAutoresizingNone;
  153. pageNumberLabel.textAlignment = NSTextAlignmentCenter;
  154. pageNumberLabel.backgroundColor = [UIColor clearColor];
  155. pageNumberLabel.textColor = [UIColor whiteColor];
  156. pageNumberLabel.font = [UIFont systemFontOfSize:16.0f];
  157. pageNumberLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
  158. pageNumberLabel.shadowColor = [UIColor blackColor];
  159. pageNumberLabel.adjustsFontSizeToFitWidth = YES;
  160. pageNumberLabel.minimumScaleFactor = 0.75f;
  161. [pageNumberView addSubview:pageNumberLabel]; // Add label view
  162. [self addSubview:pageNumberView]; // Add page numbers display view
  163. trackControl = [[ReaderTrackControl alloc] initWithFrame:self.bounds]; // Track control view
  164. [trackControl addTarget:self action:@selector(trackViewTouchDown:) forControlEvents:UIControlEventTouchDown];
  165. [trackControl addTarget:self action:@selector(trackViewValueChanged:) forControlEvents:UIControlEventValueChanged];
  166. [trackControl addTarget:self action:@selector(trackViewTouchUp:) forControlEvents:UIControlEventTouchUpOutside];
  167. [trackControl addTarget:self action:@selector(trackViewTouchUp:) forControlEvents:UIControlEventTouchUpInside];
  168. [self addSubview:trackControl]; // Add the track control and thumbs view
  169. document = object; // Retain the document object for our use
  170. [self updatePageNumberText:[document.pageNumber integerValue]];
  171. miniThumbViews = [NSMutableDictionary new]; // Small thumbs
  172. }
  173. return self;
  174. }
  175. - (void)removeFromSuperview
  176. {
  177. [trackTimer invalidate]; [enableTimer invalidate];
  178. [super removeFromSuperview];
  179. }
  180. - (void)layoutSubviews
  181. {
  182. CGRect controlRect = CGRectInset(self.bounds, 4.0f, 0.0f);
  183. CGFloat thumbWidth = (THUMB_SMALL_WIDTH + THUMB_SMALL_GAP);
  184. NSInteger thumbs = (controlRect.size.width / thumbWidth);
  185. NSInteger pages = [document.pageCount integerValue]; // Pages
  186. if (thumbs > pages) thumbs = pages; // No more than total pages
  187. CGFloat controlWidth = ((thumbs * thumbWidth) - THUMB_SMALL_GAP);
  188. controlRect.size.width = controlWidth; // Update control width
  189. CGFloat widthDelta = (self.bounds.size.width - controlWidth);
  190. NSInteger X = (widthDelta * 0.5f); controlRect.origin.x = X;
  191. trackControl.frame = controlRect; // Update track control frame
  192. if (pageThumbView == nil) // Create the page thumb view when needed
  193. {
  194. CGFloat heightDelta = (controlRect.size.height - THUMB_LARGE_HEIGHT);
  195. NSInteger thumbY = (heightDelta * 0.5f); NSInteger thumbX = 0; // Thumb X, Y
  196. CGRect thumbRect = CGRectMake(thumbX, thumbY, THUMB_LARGE_WIDTH, THUMB_LARGE_HEIGHT);
  197. pageThumbView = [[ReaderPagebarThumb alloc] initWithFrame:thumbRect]; // Create the thumb view
  198. pageThumbView.layer.zPosition = 1.0f; // Z position so that it sits on top of the small thumbs
  199. [trackControl addSubview:pageThumbView]; // Add as the first subview of the track control
  200. }
  201. [self updatePageThumbView:[document.pageNumber integerValue]]; // Update page thumb view
  202. NSInteger strideThumbs = (thumbs - 1); if (strideThumbs < 1) strideThumbs = 1;
  203. CGFloat stride = ((CGFloat)pages / (CGFloat)strideThumbs); // Page stride
  204. CGFloat heightDelta = (controlRect.size.height - THUMB_SMALL_HEIGHT);
  205. NSInteger thumbY = (heightDelta * 0.5f); NSInteger thumbX = 0; // Initial X, Y
  206. CGRect thumbRect = CGRectMake(thumbX, thumbY, THUMB_SMALL_WIDTH, THUMB_SMALL_HEIGHT);
  207. NSMutableDictionary *thumbsToHide = [miniThumbViews mutableCopy];
  208. for (NSInteger thumb = 0; thumb < thumbs; thumb++) // Iterate through needed thumbs
  209. {
  210. NSInteger page = ((stride * thumb) + 1); if (page > pages) page = pages; // Page
  211. NSNumber *key = [NSNumber numberWithInteger:page]; // Page number key for thumb view
  212. ReaderPagebarThumb *smallThumbView = [miniThumbViews objectForKey:key]; // Thumb view
  213. if (smallThumbView == nil) // We need to create a new small thumb view for the page number
  214. {
  215. CGSize size = CGSizeMake(THUMB_SMALL_WIDTH, THUMB_SMALL_HEIGHT); // Maximum thumb size
  216. NSURL *fileURL = document.fileURL; NSString *guid = document.guid; NSString *phrase = document.password;
  217. smallThumbView = [[ReaderPagebarThumb alloc] initWithFrame:thumbRect small:YES]; // Create a small thumb view
  218. ReaderThumbRequest *thumbRequest = [ReaderThumbRequest newForView:smallThumbView fileURL:fileURL password:phrase guid:guid page:page size:size];
  219. UIImage *image = [[ReaderThumbCache sharedInstance] thumbRequest:thumbRequest priority:NO]; // Request the thumb
  220. if ([image isKindOfClass:[UIImage class]]) [smallThumbView showImage:image]; // Use thumb image from cache
  221. [trackControl addSubview:smallThumbView]; [miniThumbViews setObject:smallThumbView forKey:key];
  222. }
  223. else // Resue existing small thumb view for the page number
  224. {
  225. smallThumbView.hidden = NO; [thumbsToHide removeObjectForKey:key];
  226. if (CGRectEqualToRect(smallThumbView.frame, thumbRect) == false)
  227. {
  228. smallThumbView.frame = thumbRect; // Update thumb frame
  229. }
  230. }
  231. thumbRect.origin.x += thumbWidth; // Next thumb X position
  232. }
  233. [thumbsToHide enumerateKeysAndObjectsUsingBlock: // Hide unused thumbs
  234. ^(id key, id object, BOOL *stop)
  235. {
  236. ReaderPagebarThumb *thumb = object; thumb.hidden = YES;
  237. }
  238. ];
  239. }
  240. - (void)updatePagebarViews
  241. {
  242. NSInteger page = [document.pageNumber integerValue]; // #
  243. [self updatePageNumberText:page]; // Update page number text
  244. [self updatePageThumbView:page]; // Update page thumb view
  245. }
  246. - (void)updatePagebar
  247. {
  248. if (self.hidden == NO) // Only if visible
  249. {
  250. [self updatePagebarViews]; // Update views
  251. }
  252. }
  253. - (void)hidePagebar
  254. {
  255. if (self.hidden == NO) // Only if visible
  256. {
  257. [UIView animateWithDuration:0.25 delay:0.0
  258. options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
  259. animations:^(void)
  260. {
  261. self.alpha = 0.0f;
  262. }
  263. completion:^(BOOL finished)
  264. {
  265. self.hidden = YES;
  266. }
  267. ];
  268. }
  269. }
  270. - (void)showPagebar
  271. {
  272. if (self.hidden == YES) // Only if hidden
  273. {
  274. [self updatePagebarViews]; // Update views first
  275. [UIView animateWithDuration:0.25 delay:0.0
  276. options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
  277. animations:^(void)
  278. {
  279. self.hidden = NO;
  280. self.alpha = 1.0f;
  281. }
  282. completion:NULL
  283. ];
  284. }
  285. }
  286. #pragma mark - ReaderTrackControl action methods
  287. - (void)trackTimerFired:(NSTimer *)timer
  288. {
  289. [trackTimer invalidate]; trackTimer = nil; // Cleanup timer
  290. if (trackControl.tag != [document.pageNumber integerValue]) // Only if different
  291. {
  292. [delegate pagebar:self gotoPage:trackControl.tag]; // Go to document page
  293. }
  294. }
  295. - (void)enableTimerFired:(NSTimer *)timer
  296. {
  297. [enableTimer invalidate]; enableTimer = nil; // Cleanup timer
  298. trackControl.userInteractionEnabled = YES; // Enable track control interaction
  299. }
  300. - (void)restartTrackTimer
  301. {
  302. if (trackTimer != nil) { [trackTimer invalidate]; trackTimer = nil; } // Invalidate and release previous timer
  303. trackTimer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(trackTimerFired:) userInfo:nil repeats:NO];
  304. }
  305. - (void)startEnableTimer
  306. {
  307. if (enableTimer != nil) { [enableTimer invalidate]; enableTimer = nil; } // Invalidate and release previous timer
  308. enableTimer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(enableTimerFired:) userInfo:nil repeats:NO];
  309. }
  310. - (NSInteger)trackViewPageNumber:(ReaderTrackControl *)trackView
  311. {
  312. CGFloat controlWidth = trackView.bounds.size.width; // View width
  313. CGFloat stride = (controlWidth / [document.pageCount integerValue]);
  314. NSInteger page = (trackView.value / stride); // Integer page number
  315. return (page + 1); // + 1
  316. }
  317. - (void)trackViewTouchDown:(ReaderTrackControl *)trackView
  318. {
  319. NSInteger page = [self trackViewPageNumber:trackView]; // Page
  320. if (page != [document.pageNumber integerValue]) // Only if different
  321. {
  322. [self updatePageNumberText:page]; // Update page number text
  323. [self updatePageThumbView:page]; // Update page thumb view
  324. [self restartTrackTimer]; // Start the track timer
  325. }
  326. trackView.tag = page; // Start page tracking
  327. }
  328. - (void)trackViewValueChanged:(ReaderTrackControl *)trackView
  329. {
  330. NSInteger page = [self trackViewPageNumber:trackView]; // Page
  331. if (page != trackView.tag) // Only if the page number has changed
  332. {
  333. [self updatePageNumberText:page]; // Update page number text
  334. [self updatePageThumbView:page]; // Update page thumb view
  335. trackView.tag = page; // Update the page tracking tag
  336. [self restartTrackTimer]; // Restart the track timer
  337. }
  338. }
  339. - (void)trackViewTouchUp:(ReaderTrackControl *)trackView
  340. {
  341. [trackTimer invalidate]; trackTimer = nil; // Cleanup
  342. if (trackView.tag != [document.pageNumber integerValue]) // Only if different
  343. {
  344. trackView.userInteractionEnabled = NO; // Disable track control interaction
  345. [delegate pagebar:self gotoPage:trackView.tag]; // Go to document page
  346. [self startEnableTimer]; // Start track control enable timer
  347. }
  348. trackView.tag = 0; // Reset page tracking
  349. }
  350. @end
  351. #pragma mark -
  352. //
  353. // ReaderTrackControl class implementation
  354. //
  355. @implementation ReaderTrackControl
  356. {
  357. CGFloat _value;
  358. }
  359. #pragma mark - Properties
  360. @synthesize value = _value;
  361. #pragma mark - ReaderTrackControl instance methods
  362. - (instancetype)initWithFrame:(CGRect)frame
  363. {
  364. if ((self = [super initWithFrame:frame]))
  365. {
  366. self.autoresizesSubviews = NO;
  367. self.userInteractionEnabled = YES;
  368. self.contentMode = UIViewContentModeRedraw;
  369. self.autoresizingMask = UIViewAutoresizingNone;
  370. self.backgroundColor = [UIColor clearColor];
  371. self.exclusiveTouch = YES;
  372. }
  373. return self;
  374. }
  375. - (CGFloat)limitValue:(CGFloat)valueX
  376. {
  377. CGFloat minX = self.bounds.origin.x; // 0.0f;
  378. CGFloat maxX = (self.bounds.size.width - 1.0f);
  379. if (valueX < minX) valueX = minX; // Minimum X
  380. if (valueX > maxX) valueX = maxX; // Maximum X
  381. return valueX;
  382. }
  383. #pragma mark - UIControl subclass methods
  384. - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
  385. {
  386. CGPoint point = [touch locationInView:self]; // Touch point
  387. _value = [self limitValue:point.x]; // Limit control value
  388. return YES;
  389. }
  390. - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
  391. {
  392. if (self.touchInside == YES) // Only if inside the control
  393. {
  394. CGPoint point = [touch locationInView:touch.view]; // Touch point
  395. CGFloat x = [self limitValue:point.x]; // Potential new control value
  396. if (x != _value) // Only if the new value has changed since the last time
  397. {
  398. _value = x; [self sendActionsForControlEvents:UIControlEventValueChanged];
  399. }
  400. }
  401. return YES;
  402. }
  403. - (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
  404. {
  405. CGPoint point = [touch locationInView:self]; // Touch point
  406. _value = [self limitValue:point.x]; // Limit control value
  407. }
  408. @end
  409. #pragma mark -
  410. //
  411. // ReaderPagebarThumb class implementation
  412. //
  413. @implementation ReaderPagebarThumb
  414. #pragma mark - ReaderPagebarThumb instance methods
  415. - (instancetype)initWithFrame:(CGRect)frame
  416. {
  417. return [self initWithFrame:frame small:NO];
  418. }
  419. - (instancetype)initWithFrame:(CGRect)frame small:(BOOL)small
  420. {
  421. if ((self = [super initWithFrame:frame])) // Superclass init
  422. {
  423. CGFloat value = (small ? 0.6f : 0.7f); // Size based alpha value
  424. UIColor *background = [UIColor colorWithWhite:0.8f alpha:value];
  425. self.backgroundColor = background; imageView.backgroundColor = background;
  426. imageView.layer.borderColor = [UIColor colorWithWhite:0.4f alpha:0.6f].CGColor;
  427. imageView.layer.borderWidth = 1.0f; // Give the thumb image view a border
  428. }
  429. return self;
  430. }
  431. @end
  432. #pragma mark -
  433. //
  434. // ReaderPagebarShadow class implementation
  435. //
  436. @implementation ReaderPagebarShadow
  437. #pragma mark - ReaderPagebarShadow class methods
  438. + (Class)layerClass
  439. {
  440. return [CAGradientLayer class];
  441. }
  442. #pragma mark - ReaderPagebarShadow instance methods
  443. - (instancetype)initWithFrame:(CGRect)frame
  444. {
  445. if ((self = [super initWithFrame:frame]))
  446. {
  447. self.autoresizesSubviews = NO;
  448. self.userInteractionEnabled = NO;
  449. self.contentMode = UIViewContentModeRedraw;
  450. self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  451. self.backgroundColor = [UIColor clearColor];
  452. CAGradientLayer *layer = (CAGradientLayer *)self.layer;
  453. UIColor *blackColor = [UIColor colorWithWhite:0.42f alpha:1.0f];
  454. UIColor *clearColor = [UIColor colorWithWhite:0.42f alpha:0.0f];
  455. layer.colors = [NSArray arrayWithObjects:(id)clearColor.CGColor, (id)blackColor.CGColor, nil];
  456. }
  457. return self;
  458. }
  459. @end