UIPickerView UIToolbar tintColor随机变化

时间:2016-01-02 13:11:54

标签: ios swift uipickerview uitoolbar

我的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
}

这些是来自设备和屏幕截图的屏幕截图模拟器。模拟器显示正常,但设备正在改变颜色。

模拟器:

Simulator Screen Shot

设备:

Real Device Screen Shot

0 个答案:

没有答案