I have a viewController
with a UIPickerView
and a UIDatePicker
as shown in the screenshot from my storyboard
as below.
I tried adding runtime attribute as explained here. But following it only changed the font color of the initially highlighted text.
I want to change the color of text in my both pickerView and datePicker to white. I am unaware of how can I achieve it.
you need to write this line to change date picker text color,
self.datePicker.setValue(UIColor.white, forKeyPath: "textColor")
It will change textcolor of UIDatePicker
And For PickeView
, You have to set attributed string like,
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
return NSAttributedString(string: "Your Text", attributes: [NSForegroundColorAttributeName:UIColor.blue])
}
These two lines saved the day for me.
NepaliDatePicker.setValue(UIColor.white, forKey: "textColor")
EnglishDatePicker.setValue(UIColor.white, forKey: "textColor")
You can use "viewForRow" delegate method for "UIPickerView"
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView {
// Your custom view with custom font here
}
For UIDatePicker you can't change font but you can use this code to change textColor.
datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")
datePicker.datePickerMode = .CountDownTimer
datePicker.datePickerMode = .DateAndTime
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With