Repository navigation
Expand file tree
/
Copy pathViewController.swift
More file actions
executable file
路100 lines (81 loc) 路 3.3 KB
/
Copy pathViewController.swift
File metadata and controls
executable file
路100 lines (81 loc) 路 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//
// ViewController.swift
// Example
//
// Created by Heberti Almeida on 08/04/15.
// Copyright (c) 2015 Folio Reader. All rights reserved.
//
import UIKit
import FolioReaderKit
class ViewController: UIViewController {
@IBOutlet weak var bookOne: UIButton?
@IBOutlet weak var bookTwo: UIButton?
let folioReader = FolioReader()
override func viewDidLoad() {
super.viewDidLoad()
self.bookOne?.tag = Epub.bookOne.rawValue
self.bookTwo?.tag = Epub.bookTwo.rawValue
self.setCover(self.bookOne, index: 0)
self.setCover(self.bookTwo, index: 1)
}
private func readerConfiguration(forEpub epub: Epub) -> FolioReaderConfig {
let config = FolioReaderConfig(withIdentifier: epub.readerIdentifier)
config.shouldHideNavigationOnTap = epub.shouldHideNavigationOnTap
config.scrollDirection = epub.scrollDirection
// See more at FolioReaderConfig.swift
// config.canChangeScrollDirection = false
// config.enableTTS = false
// config.displayTitle = true
// config.allowSharing = false
// config.tintColor = UIColor.blueColor()
// config.toolBarTintColor = UIColor.redColor()
// config.toolBarBackgroundColor = UIColor.purpleColor()
// config.menuTextColor = UIColor.brownColor()
// config.menuBackgroundColor = UIColor.lightGrayColor()
// config.hidePageIndicator = true
// config.realmConfiguration = Realm.Configuration(fileURL: FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("highlights.realm"))
// Custom sharing quote background
config.quoteCustomBackgrounds = []
if let image = UIImage(named: "demo-bg") {
let customImageQuote = QuoteImage(withImage: image, alpha: 0.6, backgroundColor: UIColor.black)
config.quoteCustomBackgrounds.append(customImageQuote)
}
let textColor = UIColor(red:0.86, green:0.73, blue:0.70, alpha:1.0)
let customColor = UIColor(red:0.30, green:0.26, blue:0.20, alpha:1.0)
let customQuote = QuoteImage(withColor: customColor, alpha: 1.0, textColor: textColor)
config.quoteCustomBackgrounds.append(customQuote)
return config
}
fileprivate func open(epub: Epub) {
guard let bookPath = epub.bookPath else {
return
}
let readerConfiguration = self.readerConfiguration(forEpub: epub)
folioReader.presentReader(parentViewController: self, withEpubPath: bookPath, andConfig: readerConfiguration, shouldRemoveEpub: false)
}
private func setCover(_ button: UIButton?, index: Int) {
guard
let epub = Epub(rawValue: index),
let bookPath = epub.bookPath else {
return
}
do {
if let image = try FolioReader.getCoverImage(bookPath) {
button?.setBackgroundImage(image, for: .normal)
}
} catch let e as FolioReaderError {
print(e.localizedDescription)
} catch {
print("Unkown error")
}
}
}
// MARK: - IBAction
extension ViewController {
@IBAction func didOpen(_ sender: AnyObject) {
guard let epub = Epub(rawValue: sender.tag) else {
return
}
self.open(epub: epub)
}
}