Einige Optionen, auf die ich stieß, waren das Festlegen des Titels des Ansichtssteuerelements zu einer Zeichenfolge mit einem Leerzeichen hinzufügen und auch eine benutzerdefinierte Schaltfläche hinzufügen.
Die benutzerdefinierte Schaltfläche schien auch die native Swipe-to-Pop-Geste zu entfernen, also habe ich mich für diesen Ansatz entschieden.
Code: Select all
extension UINavigationBar {
func applyAppearance(backgroundColor: UIColor, textColor: UIColor) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = backgroundColor
appearance.shadowColor = .clear
appearance.titleTextAttributes = [.foregroundColor: textColor]
// This removes the text from all back buttons
let backButtonAppearance = UIBarButtonItemAppearance(style: .plain)
backButtonAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.clear]
appearance.backButtonAppearance = backButtonAppearance
tintColor = textColor
standardAppearance = appearance
scrollEdgeAppearance = appearance
compactScrollEdgeAppearance = appearance
}
}

Also begann ich nach Möglichkeiten zu suchen, diesen Abstand zu erhöhen Polsterung/Rand links auf der Rückseite Chevron
Ich habe Folgendes versucht:
Code: Select all
// This didn't change the back button's position but impacted my search bar
layoutMargins = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 0)
// This did nothing as well, probably as the name suggests, it changes the text position rather than the image
let backButtonAppearance = UIBarButtonItemAppearance(style: .plain)
backButtonAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 20, vertical: 0)
Code: Select all
extension UINavigationBar {
func applyAppearance(backgroundColor: UIColor, textColor: UIColor) {
let appearance = UINavigationBarAppearance()
if let image = UIImage(named: "chevron.left")?.withRenderingMode(.alwaysOriginal) {
appearance.setBackIndicatorImage(image, transitionMaskImage: image)
}
standardAppearance = appearance
scrollEdgeAppearance = appearance
compactScrollEdgeAppearance = appearance
}
}
Code: Select all
if let image = UIImage(systemName: "chevron.down")?.withRenderingMode(.alwaysOriginal) {
UINavigationBar.appearance().backIndicatorTransitionMaskImage = image
UINavigationBar.appearance().backIndicatorImage = image
}
Eine Frage, die Sie vielleicht stellen könnten, ist, ob ich anrufe Dies ist an der richtigen Stelle, es geschieht nicht beim Start der App, sondern wenn der Nav Controller initialisiert wird und die meisten meiner anderen Stile angewendet werden.
Kann mir bitte jemand einen Vorschlag machen, was ich ändern kann? Das Bild und die Position der Zurück-Schaltfläche?
Ich möchte nicht verlieren die Swipe-to-Pop-Geste, daher zögere ich etwas, eine benutzerdefinierte Navigationsleistenschaltfläche zu erstellen.
Ich kann mir Apps wie Medium und Spotify vorstellen, die über ein eigenes Navigations-Zurück-Schaltflächenbild, benutzerdefinierte Auffüllung usw. verfügen die Swipe-to-Pop-Geste.