Skip to content

Commit

Permalink
Fix to work well to set background color for iOS version lower than 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pisces committed Jun 1, 2021
1 parent 7d18f6b commit 589b77f
Showing 1 changed file with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ open class CompatibleNavigationBarAppearance {
// MARK: - Open Properties

open var isHidden = false
open var isTranslucent = false
open var backgroundImageContentMode: UIView.ContentMode = .scaleToFill
open var titlePositionAdjustment: UIOffset = .zero
open var tintColor: UIColor = .systemBlue
Expand Down Expand Up @@ -92,14 +93,13 @@ open class CompatibleNavigationBarAppearance {
// MARK: - Internal Methods

func apply(to navigationBar: UINavigationBar) {
navigationBar.isTranslucent = isTranslucent
navigationBar.tintColor = tintColor

setIsTranslucent(to: navigationBar)

if #available(iOS 13.0, *) {
return
}

navigationBar.barTintColor = backgroundColor
navigationBar.backIndicatorImage = backIndicatorImage
navigationBar.backIndicatorTransitionMaskImage = backIndicatorTransitionMaskImage
Expand Down Expand Up @@ -157,19 +157,6 @@ open class CompatibleNavigationBarAppearance {
}
return appearance
}

// MARK: - Private Methods

private func setIsTranslucent(to navigationBar: UINavigationBar) {
switch backgroundMode {
case .default,
.none,
.transparent:
navigationBar.isTranslucent = true
case .opaque:
navigationBar.isTranslucent = false
}
}
}

private extension UIView {
Expand Down

0 comments on commit 589b77f

Please sign in to comment.