ReaderHive/ReaderHive/Base/Extension/UINavigationBar+NRAdd.swift
2025-12-08 16:46:19 +08:00

54 lines
1.7 KiB
Swift

//
// UINavigationBar+NRAdd.swift
// ReaderHive
//
// Created by on 2025/11/25.
//
import UIKit
extension UINavigationBar {
static let titleFont = UIFont.font(ofSize: 16, weight: .semibold)
static let titleWhiteColor = UIColor.white
static let titleBlackColor = UIColor.black
static func defaultAppearance() -> UINavigationBarAppearance {
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.backgroundColor = .clear
navBarAppearance.backgroundEffect = nil
navBarAppearance.shadowColor = UIColor.clear
navBarAppearance.titleTextAttributes = [
NSAttributedString.Key.font : UINavigationBar.titleFont,
NSAttributedString.Key.foregroundColor : UINavigationBar.titleWhiteColor
]
return navBarAppearance
}
}
extension UINavigationBar {
func nr_setTranslucent(isTranslucent: Bool) {
self.isTranslucent = isTranslucent
}
func nr_setBackgroundColor(backgroundColor: UIColor?) {
let appearance = self.standardAppearance
appearance.backgroundColor = backgroundColor
self.standardAppearance = appearance
self.scrollEdgeAppearance = appearance
}
func nr_setTitleTextAttributes(titleTextAttributes: [NSAttributedString.Key : Any]?) {
let appearance = self.standardAppearance
if let titleTextAttributes = titleTextAttributes {
appearance.titleTextAttributes = titleTextAttributes
}
self.scrollEdgeAppearance = appearance
self.standardAppearance = appearance
}
}