104 lines
3.3 KiB
Swift
104 lines
3.3 KiB
Swift
//
|
|
// RDReaderBottomToolView.swift
|
|
// RDReaderDemo
|
|
//
|
|
// Created by yangsq on 2021/8/10.
|
|
//
|
|
|
|
import UIKit
|
|
import SnapKit
|
|
|
|
public class RDReaderBottomToolView: RDReaderToolView, SSEventTrigger {
|
|
enum Event {
|
|
case chapterList, highlight, settings, darkAndLight
|
|
}
|
|
private lazy var containerView: UIStackView = {
|
|
let stackView = UIStackView()
|
|
stackView.distribution = .fillEqually
|
|
stackView.axis = .horizontal
|
|
stackView.spacing = 20
|
|
return stackView
|
|
}()
|
|
|
|
lazy var chapterListButton: TintColorButton = {
|
|
let button = TintColorButton(type: .system)
|
|
button.setImage(toolbarImage(named: "read_edit_chapterlist", fallbackSystemName: "list.bullet"), for: .normal)
|
|
addSubview(button)
|
|
button.addTarget(self, action: #selector(chapterListAction), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
lazy var settingsButton: TintColorButton = {
|
|
let button = TintColorButton(type: .system)
|
|
button.setImage(toolbarImage(named: "read_edit_font", fallbackSystemName: "textformat"), for: .normal)
|
|
addSubview(button)
|
|
button.addTarget(self, action: #selector(settingsAction), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
lazy var highlightButton: TintColorButton = {
|
|
let button = TintColorButton(type: .system)
|
|
button.setImage(UIImage(systemName: "highlighter"), for: .normal)
|
|
addSubview(button)
|
|
button.addTarget(self, action: #selector(highlightAction), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
|
|
lazy var lightModeButton: TintColorButton = {
|
|
let button = TintColorButton(type: .system)
|
|
button.setImage(toolbarImage(named: "read_edit_night", fallbackSystemName: "moon.fill"), for: .normal)
|
|
addSubview(button)
|
|
button.addTarget(self, action: #selector(lightAndDarkModeAction), for: .touchUpInside)
|
|
return button
|
|
}()
|
|
|
|
override func makeUI() {
|
|
super.makeUI()
|
|
addSubview(containerView)
|
|
containerView.addArrangedSubview(chapterListButton)
|
|
containerView.addArrangedSubview(highlightButton)
|
|
containerView.addArrangedSubview(settingsButton)
|
|
containerView.addArrangedSubview(lightModeButton)
|
|
|
|
containerView.snp.makeConstraints { make in
|
|
make.left.equalTo(16)
|
|
make.top.equalTo(0)
|
|
make.right.equalTo(-16)
|
|
make.bottom.equalTo(-RDReaderCommon.safeAreaInsets.bottom)
|
|
}
|
|
|
|
}
|
|
|
|
@objc private func chapterListAction() {
|
|
if let trigger = self.triggerEvent {
|
|
trigger(.chapterList)
|
|
}
|
|
}
|
|
|
|
@objc private func settingsAction() {
|
|
if let trigger = self.triggerEvent {
|
|
trigger(.settings)
|
|
}
|
|
}
|
|
|
|
@objc private func highlightAction() {
|
|
if let trigger = self.triggerEvent {
|
|
trigger(.highlight)
|
|
}
|
|
}
|
|
|
|
@objc private func lightAndDarkModeAction() {
|
|
if let trigger = self.triggerEvent {
|
|
trigger(.darkAndLight)
|
|
}
|
|
}
|
|
|
|
private func toolbarImage(named: String, fallbackSystemName: String) -> UIImage? {
|
|
if let image = UIImage(named: named) {
|
|
return image.withRenderingMode(.alwaysOriginal)
|
|
}
|
|
return UIImage(systemName: fallbackSystemName)
|
|
}
|
|
}
|