Was ist der richtige Weg, um die Pfeiltönung der Zurück-Schaltfläche in iOS 13 einzustellen?


11

In iOS 13 führte Apple das neue Proxy-Objekt UINavigationBarAppearance ein, um das Erscheinungsbild der Navigationsleiste festzulegen. Ich konnte fast alles einstellen, was ich brauchte, bis auf eine kleine Sache. Der Pfeil der Zurück-Schaltfläche wird immer mit blauer Tönungsfarbe gerendert, und ich habe keine Ahnung, wie ich ihn auf die gewünschte Farbe einstellen soll. Ich verwende den alten [[UINavigationBar appearance] setTintColor:]Weg, aber ich denke, es muss einen Weg geben, dies mit der UINavigationBarAppearance-Objekt-API zu tun. Hat jemand eine Idee wie?

Antworten:


1

Die neue Methode zum Festlegen der Farbe der Zurück-Schaltfläche für das Erscheinungsbild (Proxy) lautet:

let appearance = UINavigationBarAppearance()

// Apply the configuration option of your choice
appearance.configureWithTransparentBackground()

// Create button appearance, with the custom color
let buttonAppearance = UIBarButtonItemAppearance(style: .plain)
buttonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.white]

// Apply button appearance
appearance.buttonAppearance = buttonAppearance

// Apply tint to the back arrow "chevron"
UINavigationBar.appearance().tintColor = UIColor.whiteI

// Apply proxy
UINavigationBar.appearance().standardAppearance = appearance

// Perhaps you'd want to set these as well depending on your design:
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance

5

Ich habe ein benutzerdefinierte Navigation - Controller - Setup in meiner app, die modifiziert navigationBars titleTextAttributes, tintColorund andere , in Abhängigkeit von unterschiedlichen Szenarien.

Beim Ausführen der App unter iOS 13 hatte der backBarButtonItemPfeil die Standardfarbe Blau. Der View-Debugger zeigte, dass nur die UIBarButtonItems UIImageViewdiesen blauen Farbton hatten.

Am Ende habe ich navigationBar.tintColorzweimal festgelegt, dass die Farbe geändert werden soll ...

public class MyNavigationController: UINavigationController, UINavigationControllerDelegate {

    public var preferredNavigationBarTintColor: UIColor?

    override public func viewDidLoad() {
        super.viewDidLoad()
        delegate = self
    }


    public func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {

        // if you want to change color, you have to set it twice
        viewController.navigationController?.navigationBar.tintColor = .none
        viewController.navigationController?.navigationBar.tintColor = preferredNavigationBarTintColor ?? .white

        // following line removes the text from back button
        self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

    }


Der seltsamste Teil bei der Suche nach einer Lösung war das inkonsistente Ergebnis, was mich glauben lässt, dass es mit der Anzeige von Lebenszyklus- und / oder Erscheinungsanimationen oder dem Xcode-Cache zusammenhängt :)


2
Ich kann nicht alle Hack-Fixes glauben, die wir machen müssen, um iOS 13 zu unterstützen: / Danke übrigens für das Update!
— Sreejith

Seltsam, ich muss es nicht einstellen .noneoder nil, ich gebe ihm nur eine Farbe, nachdem ich das Aussehen eingestellt habe und es funktioniert einfach
— Mark
Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.