6

I have created a formatted display of a date object in a table cells and used UIDatePicker to edit those values.

But I am unable to edit the tint color of the text and the background color.

The first screenshot is the actual undesired result:

The actual UIDatepicker

The second screenshot is the desired result:

enter image description here

Here is a link to the project : https://www.dropbox.com/sh/m74tnghpqeah8o7/AAA-rMlGe_mhqiuEkDhbApsUa?dl=0

AziCode
  • 2,510
  • 6
  • 27
  • 53

2 Answers2

13

@AziCode

Add the below line in your func updateDatePicker() , if you like to get the exact color use RGB color coding with UiColor

targetedDatePicker.backgroundColor = UIColor.blueColor()
targetedDatePicker.setValue(UIColor.greenColor(), forKeyPath: "textColor")
targetedDatePicker.setValue(0.8, forKeyPath: "alpha")

And refer the link and sample codes for same examples :- http://blog.deeplink.me/post/81386967477/how-to-easily-customize-uidatepicker-for-ios

can I change the font color of the datePicker in iOS7?

Community
  • 1
  • 1
Max
  • 5,380
  • 6
  • 42
  • 66
  • Thanks, the code for the background color works fine. Is there a similar solution to change the text color ( in Swift instead of Objective-C) ? – AziCode Jul 02 '15 at 20:12
  • @AziCode see my answer it has code to change the text color as well. – Max Jul 02 '15 at 20:38
  • 1
    The code for the text doesn't work properly. the color changes only when you change the date. And then you end up with the date in green and the time in black. Do you think there is a way the whole line in green for example. – AziCode Jul 02 '15 at 21:02
3

Normaly i have good idea,but just change font color:

[self.datePicker setValue:[UIColor whiteColor] forKeyPath:@"textColor"];
    SEL selector = NSSelectorFromString( @"setHighlightsToday:" );
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature :
                                [UIDatePicker
                                 instanceMethodSignatureForSelector:selector]];
    BOOL no = NO;
    [invocation setSelector:selector];
    [invocation setArgument:&no atIndex:2];
    [invocation invokeWithTarget:self.datePicker];
Genevios
  • 1,115
  • 1
  • 16
  • 29