【发布时间】:2017-06-28 12:47:12
【问题描述】:
我正在制作一个应用程序,其中有 4 个选项卡,最后一个选项卡用于更改为暗模式(更改标签颜色、背景颜色、键盘颜色和 pickerView 颜色)。 func 是我改变颜色的地方。一切正常,除了 pickerView 没有改变颜色,所以我需要帮助。
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
}
}
}
【问题讨论】:
-
欢迎来到 SO。你能更具体地谈谈你的问题吗?你得到什么错误,什么不起作用?
标签: ios arrays swift uipickerview viewwillappear