andreamazz / AMScrollingNavbar

Scrollable UINavigationBar that follows the scrolling of a UIScrollView
MIT License
6.05k stars 634 forks source link

The back button text color changed from transparent to black. #394

Closed y-okudera closed 4 years ago

y-okudera commented 4 years ago

Hi, @andreamazz Thank you for the cool library.

After hiding the navigation bar, the back button text color changed from transparent to black. And I solved the problem.

Before After
before after

Updating the navigation appearance in sample app is the following.

extension UINavigationController {
    func setupCustomNavigation() {
        let clear = [NSAttributedString.Key.foregroundColor: UIColor.clear]

        if #available(iOS 13.0, *) {
            let barAppearance = UINavigationBarAppearance()

            // Hide back button title.
            let barButtonAppearance = UIBarButtonItemAppearance()
            barButtonAppearance.normal.titleTextAttributes = clear
            barButtonAppearance.highlighted.titleTextAttributes = clear
            barAppearance.backButtonAppearance = barButtonAppearance

            // Set NavigationBar background color.
            barAppearance.backgroundColor = .yellow

            self.navigationBar.standardAppearance = barAppearance
            self.navigationBar.isTranslucent = false
        }
        else {
            // Hide back button title.
            UIBarButtonItem
                .appearance(whenContainedInInstancesOf: [UINavigationBar.self])
                .setTitleTextAttributes(clear, for: .normal)

            UIBarButtonItem
                .appearance(whenContainedInInstancesOf: [UINavigationBar.self])
                .setTitleTextAttributes(clear, for: .highlighted)

            // Set NavigationBar background color.
            self.navigationBar.barTintColor = .yellow
            self.navigationBar.isTranslucent = false
        }
    }
}

Best regards,

y-okudera commented 4 years ago

This issue also occurs on non-iOS 13, so I updated the title.

andreamazz commented 4 years ago

Nice catch, thanks for your contribution!