Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change UIDatePicker font color?

All I want to do is change the font color of the UIDatePicker. I've researched other questions but they're all involving changing other properties and customizing the entire look. All I want to do is just change the font color from black to white. I find it hard to believe that I can't do such a seemingly simple task. And why wouldn't the tint color affect it? Does it even do anything?

like image 900
Milo Avatar asked Jan 02 '14 01:01

Milo


People also ask

How do you change the text color?

Open your device's Settings app . Text and display. Select Color correction. Turn on Use color correction.

How do I change text color in Xcode?

Xcode Getting started with Xcode Changing The Color SchemeWith the preference pane open you can click on the 'Fonts and Colors' tab. From here you can change the source AND console background and font colors.


2 Answers

All I need (on iOS 8.x and 9.0) is this one line to change the font color:

        [my_date_picker setValue:[UIColor whiteColor] forKey:@"textColor"]; 

No subclassing or invoking of private APIs...


Note: today's current date will still be highlighted (in newer iOS versions). You can get around this by using the following code:

if ([my_date_picker respondsToSelector:sel_registerName("setHighlightsToday:")]) {  #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wundeclared-selector"          [my_date_picker performSelector:@selector(setHighlightsToday:) withObject:[NSNumber numberWithBool:NO]];  #pragma clang diagnostic pop  } 
like image 180
waffles Avatar answered Sep 21 '22 22:09

waffles


As of Swift 2.1:

picker.setValue(UIColor.whiteColor(), forKey: "textColor") picker.sendAction("setHighlightsToday:", to: nil, forEvent: nil) let date = NSDate() picker.setDate(date, animated: false) 

Instead of "today" you will see the current day,

like image 44
theDC Avatar answered Sep 21 '22 22:09

theDC