Files
ReadViewSDK/Sources/RDEpubReaderView/EPUBUI/Settings/RDEPUBReaderTheme.swift
T

85 lines
2.7 KiB
Swift

import UIKit
public struct RDEPUBReaderTheme: Equatable {
public var contentBackgroundColor: UIColor
public var contentTextColor: UIColor
public var toolBackgroundColor: UIColor
public var toolControlTextColor: UIColor
public var toolControlBorderUnselectColor: UIColor
public var toolLineColor: UIColor
public init(
contentBackgroundColor: UIColor,
contentTextColor: UIColor,
toolBackgroundColor: UIColor,
toolControlTextColor: UIColor,
toolControlBorderUnselectColor: UIColor,
toolLineColor: UIColor
) {
self.contentBackgroundColor = contentBackgroundColor
self.contentTextColor = contentTextColor
self.toolBackgroundColor = toolBackgroundColor
self.toolControlTextColor = toolControlTextColor
self.toolControlBorderUnselectColor = toolControlBorderUnselectColor
self.toolLineColor = toolLineColor
}
public static let light = preset(contentBackground: .white, text: .black)
public static let dark = preset(contentBackground: .black, text: .white)
public static let yellow = preset(
contentBackground: UIColor(red: 0.89, green: 0.87, blue: 0.79, alpha: 1),
text: .black
)
public static let green = preset(
contentBackground: UIColor(red: 0.87, green: 0.91, blue: 0.82, alpha: 1),
text: .black
)
public static let pink = preset(
contentBackground: UIColor(red: 1, green: 0.89, blue: 0.91, alpha: 1),
text: .black
)
public static let blue = preset(
contentBackground: UIColor(red: 0.8, green: 0.84, blue: 0.89, alpha: 1),
text: .black
)
/// 工具条/弹出页统一用比正文背景稍深的底色(暗色主题稍亮),拉开层次对比。
private static func preset(contentBackground: UIColor, text: UIColor) -> RDEPUBReaderTheme {
RDEPUBReaderTheme(
contentBackgroundColor: contentBackground,
contentTextColor: text,
toolBackgroundColor: contentBackground.rd_chromeShade,
toolControlTextColor: text,
toolControlBorderUnselectColor: UIColor.lightGray.withAlphaComponent(0.5),
toolLineColor: UIColor.lightGray.withAlphaComponent(0.5)
)
}
}
extension RDEPUBReaderTheme {
/// Background color for the full-screen image viewer.
/// Always near-black regardless of theme, since the image is the focus.
var imageViewerBackgroundColor: UIColor {
UIColor(white: 0.0, alpha: 0.95)
}
var themeBackgroundColorCSS: String {
contentBackgroundColor.rd_cssString
}
var themeTextColorCSS: String {
contentTextColor.rd_cssString
}
}