import UIKit // MARK: - 工具栏基类 /// 阅读器工具栏的基类 /// 提供分隔线和主题适配的通用逻辑,子类只需关注具体功能按钮 open class RDEPUBReaderToolView: UIView { /// 分隔线视图 private let lineView = UIView() /// 分隔线高度 private let lineHeight: CGFloat = 0.5 override init(frame: CGRect) { super.init(frame: frame) translatesAutoresizingMaskIntoConstraints = false addSubview(lineView) } public required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } open override func layoutSubviews() { super.layoutSubviews() lineView.frame = lineFrame(in: bounds) } /// 应用主题配色到工具栏 /// - Parameter theme: 阅读器主题配置 open func apply(theme: RDEPUBReaderTheme) { backgroundColor = .white lineView.backgroundColor = UIColor.lightGray.withAlphaComponent(0.5) } /// 计算分隔线的位置和尺寸,子类可重写以调整分隔线位置(如顶部或底部) /// - Parameter bounds: 工具栏的 bounds /// - Returns: 分隔线的 frame open func lineFrame(in bounds: CGRect) -> CGRect { CGRect(x: 0, y: 0, width: bounds.width, height: lineHeight) } } // MARK: - 工具栏按钮 /// 阅读器工具栏专用按钮 /// 继承自 UIButton,用于工具栏中的功能按钮 final class RDEPUBReaderTintButton: UIButton { }