MoviaBox/ShortPlay/Base/Extension/UINavigationBar+SPAdd.swift
2025-04-09 18:24:58 +08:00

93 lines
2.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// UINavigationBar+SPAdd.swift
// ShortPlay
//
// Created by on 2025/4/8.
//
import UIKit
extension UINavigationBar {
static let sp_normalTitleFont = UIFont.fontBold(ofSize: 15)
static var sp_normalTitleColor: UIColor {
get {
return .colorFFFFFF()
}
}
/**
*/
static var sp_normalTitleTextAttributes: [NSAttributedString.Key : Any] {
get {
return [
NSAttributedString.Key.font : sp_normalTitleFont,
NSAttributedString.Key.foregroundColor : sp_normalTitleColor
]
}
}
/**
*/
static var sp_normalBackgroundColor: UIColor {
get {
return .themeColor()
}
}
@available(iOS 13.0, *)
static let navBarAppearance: UINavigationBarAppearance = {
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
//
navBarAppearance.backgroundColor = sp_normalBackgroundColor
//
navBarAppearance.backgroundEffect = nil
// clear线
navBarAppearance.shadowColor = UIColor.clear
//
navBarAppearance.titleTextAttributes = sp_normalTitleTextAttributes
return navBarAppearance
}()
func sp_setTranslucent(isTranslucent: Bool) {
self.isTranslucent = isTranslucent
}
func sp_setBackgroundColor(backgroundColor: UIColor?) {
if #available(iOS 15.0, *) {
UINavigationBar.navBarAppearance.backgroundColor = backgroundColor
self.standardAppearance = UINavigationBar.navBarAppearance
self.scrollEdgeAppearance = UINavigationBar.navBarAppearance
}
if let backgroundColor = backgroundColor {
self.setBackgroundImage(UIImage(color: backgroundColor), for: .default)
// self.barTintColor = backgroundColor
} else {
self.setBackgroundImage(UIImage(), for: .default)
// self.barTintColor = nil
}
}
func sp_setTitleTextAttributes(titleTextAttributes: [NSAttributedString.Key : Any]?) {
if #available(iOS 15.0, *) {
if let titleTextAttributes = titleTextAttributes {
UINavigationBar.navBarAppearance.titleTextAttributes = titleTextAttributes
}
self.scrollEdgeAppearance = UINavigationBar.navBarAppearance
self.standardAppearance = UINavigationBar.navBarAppearance
} else {
self.titleTextAttributes = titleTextAttributes
}
}
}