我的pickerView工具栏中有一个奇怪的问题。它在模拟器和真实设备中显示不同。我将toolBar
barTintColor
配置为背景颜色,将tintColor
配置为按钮文字颜色。
// Configuring PickerViews
private func configurePickerViews(pickerView: UIPickerView, textField: UITextField) {
pickerView.delegate = self
pickerView.backgroundColor = UIColor.whiteColor()
let toolBar = UIToolbar()
toolBar.barTintColor = DesignSettings().vetMappColor
toolBar.tintColor = UIColor.whiteColor()
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Seç", style: UIBarButtonItemStyle.Plain, target: self, action: "choosePickerMethod")
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
let cancelButton = UIBarButtonItem(title: "Vazgeç", style: UIBarButtonItemStyle.Plain, target: self, action: "cancelPickerMethod")
toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
toolBar.userInteractionEnabled = true
textField.inputAccessoryView = toolBar
textField.inputView = pickerView
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if (pickerView.tag == 1){
return citiesDatabase.getCities().count
}else{
if let city = cityTextField.text {
return citiesDatabase.getTowns(city: city).count
}
return 0
}
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if (pickerView.tag == 1){
cityTextField.text = citiesDatabase.getCities()[row]
return citiesDatabase.getCities()[row]
} else {
if let city = cityTextField.text {
townTextField.text = citiesDatabase.getTowns(city: city)[row]
return citiesDatabase.getTowns(city: city)[row]
}
return nil
}
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if (pickerView.tag == 1){
cityTextField.text = citiesDatabase.getCities()[row]
} else {
if let city = cityTextField.text {
townTextField.text = citiesDatabase.getTowns(city: city)[row]
}
}
}
// Changing Picker View Text Color Delegate
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
if (pickerView.tag == 1){
let citiesData = citiesDatabase.getCities()[row]
let citiesTitle = NSAttributedString(string: citiesData, attributes: [NSForegroundColorAttributeName:DesignSettings().vetMappColor])
return citiesTitle
}else{
if let city = cityTextField.text {
let townData = citiesDatabase.getTowns(city: city)[row]
let townTitle = NSAttributedString(string: townData, attributes: [NSForegroundColorAttributeName:DesignSettings().vetMappColor])
return townTitle
}
}
return nil
}
这些是来自设备和屏幕截图的屏幕截图模拟器。模拟器显示正常,但设备正在改变颜色。
模拟器:
设备: