Invert UIDatePicker colors in iOS 7

I want to start by posting this question on the Apple Dev forums, but due to an unsuccessful hacking attempt or whatever, the forum has been down for almost 2 weeks and I need a solution for this as soon as possible.

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

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

(mostly inverted).

I have tried several things:

  • Setting the background to black and looping through all the views of the view until I get shortcuts that show the date and change color to white. The problem is that the view has only one subtitle and the subview does not have any subheadings. Therefore, this solution does not work. (this was done in ios6).

  • Applying a filter to represent CALayer. The fact is that this is possible only on OS X, and not on iOS, for some unknown reason.

  • Game with UIApperance protocol . From what I read, this should work, but what I tried was not there, and I do not have much experience with this to understand why not.

Any ideas what I can try? Is it possible? Did I make a mistake in my approach to the problem?

+4
source share
8 answers

What you want is possible, but it will be called Custom Date Picker.

Below is a link where you will find what you want.

https://www.cocoacontrols.com/controls/simpledatepicker

If you need more, grab the loot from the link below.

https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=datepicker

+1
source

Try the following:

Put this code in - (void) viewDidLoad

[uiDatePickerOutlet setValue:[UIColor whiteColor] forKey:@"textColor"]; 
+5
source

I spent a lot of time struggling with the same problem. First I put the UIDatePicker on a black background and wondered why it is invisible ...

In the end, I set the white UIView as the background for selecting the date, so when the whole view is black, the date selection is white. It actually looks fine, although fortunately I don’t have a client who dictates the design.

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

+2
source

Ok, I understand your frustration, but iOS7 is under the NDA.
Typically, these views are created using layers, beacuse the Transform sublayer, which can make the perspective give the idea of ​​3D. I would look at sublayers if you don't see subviews.
Another reason is that I will not hack too many hierachy views / layers, switching ios <= 6 to ios7 showed that hacking is not a good idea.
The UIAppereance protocol is probably the way to go, because it forces you to change what you can change (without pushing it in the future), maybe you can set backgroundImage, try setting 1x1pixel color png blng, you should also see the string attribute or text property.

+1
source

I don't know if this is really relevant, but in Swift 3 / Xcode 8 you can just 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 
+1
source

I do not think that this can be done directly by changing the default UIDatePicker properties, although you can use custom controls for this. This can help,

MWDatePicker - https://github.com/mwermuth/MWDatePicker (found in cocoa control - https://www.cocoacontrols.com/controls/mwdatepicker )

0
source

according to iOS design resources:

You cannot customize the appearance of the date picker.

I would suggest one of the following options:

  • Redesign your user interface to use black text
  • Use customer date id
0
source

You must tell your client that his proposal is contrary to the principles of iOS 7 development, and this is true. I am not a big fan of iOS 7, but we all have to pay tribute. Your client must accept the standard iOS 7 user interface temporarily until they can make an informed decision. Developing an application based on its initial impressions is a recipe for disaster.

0
source

Source: https://habr.com/ru/post/1493904/


All Articles