Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change UIDatePicker TextColor in iOS10

Tags:

ios

swift

I had a method of changing the UIDatePicker's text color on versions of iOS before 10, but with iOS10 those solutions no longer appear to work. How could I restore the ability to change the textColor for a UIDatePicker?

   if #available(iOS 10.0, *) {
        //Not sure of a way to do something similar here.
   } else {
        //The following lines change the textColor of UIDatePicker to white in iOS9 and older.
        self.setValue(UIColor.white, forKey: "textColor")
        self.sendAction(Selector("setHighlightsToday:"), to: nil, for: nil) 
   }
like image 831
AppreciateIt Avatar asked Dec 28 '25 00:12

AppreciateIt


1 Answers

Nothing seems to have changed because I am able to achieve it even using Swift 3 as shown below.

import UIKit

class ViewController: UIViewController
{
    override func viewDidLoad()
    {
        super.viewDidLoad()

        let temp: UIDatePicker = UIDatePicker(frame: self.view.frame)
        temp.setValue(UIColor.purple, forKey: "textColor")

        view.addSubview(temp)
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
    }
}
like image 112
eshirima Avatar answered Dec 30 '25 17:12

eshirima



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!