Desidero modificare il colore della voce del pulsante della barra destra da nero a bianco. È un pulsante come icona di ricerca. Non ho ancora codificato l'implementazione della ricerca perché voglio che l'interfaccia principale sia completata per prima. Ho pensato di aver scritto i codici corretti in modo che appaia come bianco, ma sembra essere ancora nero sia nello storyboard che nel simulatore.Come cambiare tintColor di UIBarButtonItem in Swift?
Nello storyboard, l'ho anche impostato su bianco.
Ecco il mio codice, che si trova nel file AppDelegate.swift
:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Changing the status bar's colour to white
UIApplication.sharedApplication().statusBarStyle = .LightContent
// Changing the navigation controller's background colour
UINavigationBar.appearance().barTintColor = UIColor(red: 0.0/255.0, green: 165.0/255.0, blue: 227.0/255.0, alpha: 1.0)
// Changing the navigation controller's title colour
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
// Changing the colour of the bar button items
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
// Changing the tint colour of the tab bar icons
UITabBar.appearance().tintColor = UIColor(red: 0.0/255/0, green: 165.0/255.0, blue: 227.0/255.0, alpha: 1.0)
return true
}
Ecco un'immagine del simulatore:
Trovo strano che questa riga di codice non funziona Qualche soluzione?
Hai provato 'UIBarButtonItem.appearance(). TintColor = UIColor.greenColor()' –
@RashwanL L'ho provato, ma è ancora nero. Voglio che sia bianco. –
'UINavigationBar.appearance(). TintColor = UIColor.whiteColor()' dovrebbe funzionare. È necessario modificare 'tintColor' con un altro colore nel codice – Leo