Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invert UIDatePicker colors in iOS 7

Tags:

ios

ios7

I want to start by saying that i would post this question on the Apple Dev Forums but because of the hacking attempt fiasco , or whatever that was, the forum has been offline for almost 2 weeks now and i need a solution for this as soon as possible.

In iOS 7 the UIDatePicker looks like this : enter image description here

and a client asked to look like this : enter image description here

(basically inverted).

I've tried a few things:

  1. Setting the background to black and looping through all the view's subviews until i reach the labels that show the date itself and change their color to white. The problem is that The view has only one subview, and that subview doesn't have any subviews of it's own. So this solution doesn't work. (it did in ios6).

  2. Applying a filter to the view's CALayer. The thing is that this is only possible on OS X not on iOS, for some unknown reason.

  3. Playing with UIApperance protocol. From what i've read this should work but what i've tried didn't and i don't have extensive experience with this to figure out why not.

Any ideas what i can try? Is this even possible? Did i made a mistake in my approach of the problem?

like image 974
skytz Avatar asked Jul 28 '13 09:07

skytz


3 Answers

Try this out :

Put this code in -(void)viewDidLoad

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

Swift:

datePicker.setValue(UIColor.white, forKey: "textColor")
like image 155
aashish tamsya Avatar answered Nov 17 '22 08:11

aashish tamsya


Don't know if this is still relevant but on Swift 3 / Xcode 8 you can simply do this:

let datePicker = UIDatePicker()
datePicker.datePickerMode = UIDatePickerMode.date

// Sets the text color
datePicker.setValue(UIColor.white, forKey: "textColor")
// Sets the bg color
datePicker.backgroundColor = UIColor.black.withAlphaComponent(0.6)

textField.inputView = datePicker
like image 3
ygbr Avatar answered Nov 17 '22 08:11

ygbr


I spent quite a bit of time struggling with the same problem. At first, I've put a UIDatePicker on a black background and was wondering why it is invisible...

I ended up placing a white UIView as a background for the date picker, so while the whole view is black, the date picker is white. It actually looks okay, although thankfully I don't have a client who would dictate the design.

One possible argument for a client: the old, pre-iOS7 date picker, also had a predefined non-customisable background.

like image 2
Sundraw Avatar answered Nov 17 '22 07:11

Sundraw