I'm having the most frustrating dilemma. I've researched up and down and can clearly see that Apple does not want us tampering with iOS 7. Well, I want to tamper. And, the team at Mailbox clearly figured out how to do it and get approved.
The main thing that I'm trying to achieve is to change the label color to white.
My first thought was they are using a custom UIPickerView that just mimics a UIDatePicker, but I just don't think this is the case.
I zoomed in on a small fragment and discovered remnants of a normal UIDatePicker (black lines) along with clipping on the letter "W".
Now I've scoured high and low. Did some runtime hacking, messed with UIAppearance, and even dug into some private APIs just to see if this is possible.
I got close, very close, but it used a private API, and if you scrolled fast enough the labels would turn black again.
I'm completely at a loss on how to do this without a) breaking the rules or b) spending countless hours reimplementing UIDatePicker.
Mailbox, tell me your secrets! And if anyone else has any suggestions (and I mean any), please let me know.
Also, this is the closest I've gotten:
Here's a good working snippet. Tested on iOS 7.1, 8.0 and 8.1.
I've added a simple condition to break the compilation process if you're building for iOS > 8.1, because I can't be sure that this hack will work, and you don't want to have any crashes in production because of this.
The
setHighlightsToday:
selector is used becauseUIDatePicker
is using[UIColor blackColor]
by default to display the current date.This worked for me.
I need similar for my app and have ended up going the long way round. It's a real shame there isn't an easier way to simply switch to a white text version of UIDatePicker.
The code below uses a category on UILabel to force the label's text colour to be white when the setTextColor: message is sent to the label. In order to not do this for every label in the app I've filtered it to only apply if it's a subview of a UIDatePicker class. Finally, some of the labels have their colours set before they are added to their superviews. To catch these the code overrides the willMoveToSuperview: method.
It would likely be better to split the below into more than one category but I've added it all here for ease of posting.
I found the trick that set font color to any color and also dont mess up with Today label.
Here is the result:
And all the credits for this solution goes to this post in other thread: https://stackoverflow.com/a/33459744/1236334
The surefire way to do this is to iterate through subviews, and subviews of subviews, until you find the class you're looking for (in this case, some kind of UILabel) and manually set properties on it.
To find the one you're looking for I suggest you use an app like X-ray or Reveal to inspect the view hierarchy to get the exact class name, and then:
This is a very fragile way of doing things, but it doesn't technically ever call a private API, and it wouldn't scare Apple. Back in iOS 5 I used to do things like this to make UIAlertViews bigger on iPads to have more text without the embedded scroll view.
A lot of trial and error might be necessary, and it may not look pretty, but it will work.
(As a very smart guy I know said: "all the code will be lost to the compiler, like tears in rain.")