Sunday, September 25, 2022
HomeiOS Developmentios - Cannot get rid of transparency in my navigation bar

ios – Cannot get rid of transparency in my navigation bar

[ad_1]

I have a configuration class from which I set the appearance for the navigation bar:

final class AppearanceConfigurator: Configurable {
  func configure() {
    let mainColor = R.color.main()
    let secondaryColor = R.color.white()

    setupNavigationBar(mainColor: mainColor, secondaryColor: secondaryColor)
    setupControls(mainColor: mainColor, secondaryColor: secondaryColor)

    let appearance = UIToolbarAppearance()
    appearance.backgroundColor = secondaryColor
  }

  private func setupNavigationBar(mainColor: UIColor?, secondaryColor: UIColor?) {
    let navigationBar = UINavigationBar.appearance()
    let navigationBarAppearance = getNavigationBarAppearance(backgroundColor: mainColor,
                                                             textColor: secondaryColor)

    navigationBar.barTintColor = secondaryColor
    navigationBar.tintColor = secondaryColor
    navigationBar.isTranslucent = false
    navigationBar.standardAppearance = navigationBarAppearance
    navigationBar.scrollEdgeAppearance = navigationBar.standardAppearance
  }

  private func getNavigationBarAppearance(backgroundColor: UIColor?, textColor: UIColor?) -> UINavigationBarAppearance {
    let navigationBarAppearance = UINavigationBarAppearance()
    navigationBarAppearance.configureWithOpaqueBackground()
    navigationBarAppearance.backgroundColor = backgroundColor
    
    if let textColor = textColor {
        navigationBarAppearance.titleTextAttributes = [.foregroundColor: textColor]
        navigationBarAppearance.largeTitleTextAttributes = [.foregroundColor: textColor]
    }
    return navigationBarAppearance
  }

  private func setupControls(mainColor: UIColor?, secondaryColor: UIColor?) {
    UISearchBar.appearance().backgroundColor = secondaryColor
    UISearchBar.appearance().tintColor = mainColor
    UIButton.appearance().tintColor = secondaryColor
    UILabel.appearance().tintColor = secondaryColor
    UIBarButtonItem.appearance().tintColor = secondaryColor
    UIRefreshControl.appearance().tintColor = secondaryColor
  }
}

However, the color of the navigation bar is somehow transparent. What am I missing? I’ve set translucent to false and also passed standard appearance as I should have

[ad_2]

Source link

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments