Je crée une application avec 4 onglets, le dernier onglet est utilisé pour passer en mode sombre (changement de la couleur de l'étiquette, de la couleur BG, de la couleur du clavier et de la couleur du sélecteur) . La fonction est où je change la couleur. Tout fonctionne sauf le pickerView ne change pas de couleur alors c'est ce dont j'ai besoin d'aide.UIPickerView ne change pas de couleur lorsque dans viewWillAppear if statement
override func viewWillAppear(_ animated: Bool) {
if UserDefaults.standard.integer(forKey: "dark") == 1{
self.view.backgroundColor = UIColor.darkGray
UITextField.appearance().keyboardAppearance = .dark
textField.backgroundColor = UIColor.white
textField.textColor = UIColor.black
textField2.textColor = UIColor.black
textField2.backgroundColor = UIColor.white
label.textColor = UIColor.white
label.textColor = UIColor.white
labelIN1.textColor = UIColor.white
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let titleData = list[row]
let myTitle = NSAttributedString(string: titleData, attributes: [NSForegroundColorAttributeName:UIColor.black])
return myTitle
}
}else{
self.view.backgroundColor = UIColor.white
UITextField.appearance().keyboardAppearance = .light
textField.backgroundColor = UIColor.white
textField.textColor = UIColor.black
textField2.textColor = UIColor.black
textField2.backgroundColor = UIColor.white
label.textColor = UIColor.black
label.textColor = UIColor.black
labelIN1.textColor = UIColor.black
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
let titleData = list[row]
let myTitle = NSAttributedString(string: titleData, attributes: [NSForegroundColorAttributeName:UIColor.white])
return myTitle
}
}
}
Bienvenue chez SO. Pouvez-vous être plus précis concernant votre problème? Quelle erreur obtenez-vous, qu'est-ce qui ne fonctionne pas? – petezurich