ios uipickerview点击后更改文字颜色

时间:2016-10-20 20:23:22

标签: ios swift swift3 uipickerview textcolor

是否可以动态更改uipickerview的文字颜色?

我想在三次点击时更改uipickerview的textColor:

let triple_tap = UITapGestureRecognizer(target: self, action: #selector(tripleTapped))
triple_tap.numberOfTapsRequired = 3
view.addGestureRecognizer(triple_tap)


func tripleTapped() {
    self.view.backgroundColor = self.view.backgroundColor?.inverse()        
    myLabel.textColor = myLabel.textColor?.inverse()
    myPicker.backgroundColor = myPicker.backgroundColor?.inverse()
    // myPicker 
    // can't figure out out how to change the text color here? is it possible?
}

我的挑选者代表:

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
    let pickerLabel = UILabel()
    let titleData = NSString(format: "%@", myData[row])
    let myTitle = NSAttributedString(string: titleData as String, attributes: [NSFontAttributeName:UIFont(name: "Helvetica Neue", size: 20.0)!,NSForegroundColorAttributeName:UIColor.lightGray])
    pickerLabel.attributedText = myTitle
    pickerLabel.textAlignment = .center
    return pickerLabel

}

0 个答案:

没有答案