17

i just upgraded my app to iOS7 and found that date picker is transparent. It looks like I can see everything which is behind the date picker. How can I avoid this?

I tried to place date picker in another view. But still, its transparent. How can I avoid transparency of UIDatePicker? I've tried this link 1: can I change the font color of the datePicker in iOS7? but it didn't work. Thanks in advance.

Edit : I've added a UIDatePicker to a view named whiteborderview.

whiteborderview.backgroundColor = [UIColor whiteColor];

whiteborderview.alpha = 1.0;

[whiteborderview addSubview:dtPkrStart] 

and I got output like this

transparent datepicker

but still its transparent.

Edit2

I used this code and now its looking better than previous one

[UIView appearanceWhenContainedIn:[UITableView class], [UIDatePicker class], nil].backgroundColor = [UIColor colorWithWhite:1 alpha:1];

dtPkrStart.backgroundColor = [UIColor blackColor];

The date picker appearence changed like this date picker new look

Community
  • 1
  • 1
Midhun Raj
  • 201
  • 1
  • 2
  • 5

3 Answers3

55

Just change background color of your date picker

datepicker.backgroundColor = [UIColor yourcolor];
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
Maul
  • 1,179
  • 6
  • 13
  • 1
    This works fine for me: datePicker.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.95]; I used 0.95 here so there's still a little bit of transparency, but 1.0 works fine if you want it completely opaque. – Joe Strout Oct 22 '13 at 23:27
  • 5
    any idea why it doesn't work from the interface builder? – codrut Apr 09 '14 at 13:05
  • 13
    @codrut because Apple loves to poke at us iOS developers here and there. – Louie Aug 08 '14 at 02:47
  • 1
    Looks like a bug... Still here in Xcode 7.1; cannot change background color from interface builder (stays transparent whatever the setting), but works fine from code: `_datePicker.backgroundColor = [UIColor whiteColor];` – Richard Oct 26 '15 at 20:10
6

you can add a uiview with any color behind the uidatepicker. it will work for you.

Imran Ahmed
  • 1,023
  • 1
  • 11
  • 23
  • i've placed the datepicker in a view which is not transprent and applied white color for that.But the same view is placed over a transparent view(thats my requirment).But the end result is datepicker is still transparent. :( – Midhun Raj Oct 09 '13 at 06:29
  • The datepicker will remain transparent. but the view that is in background of datepicker will remove the transparency of the datepicker. its just like, if you put any color sheet behind a transparent glass – Imran Ahmed Oct 09 '13 at 06:31
  • i've done the same .but still i can see through datepicker.everything behind the view is visible. alpha content of view is set to 2:( – Midhun Raj Oct 09 '13 at 06:43
  • alpha should be between 0-1. in your case it should be 1 – Imran Ahmed Oct 09 '13 at 06:45
  • i've added screen shot – Midhun Raj Oct 09 '13 at 07:07
  • thanks, please show me the code or nib file that how you added the background view.i think the background view is transparent – Imran Ahmed Oct 09 '13 at 07:09
  • its not resolved yet.i've replaced the white bordered view with a imageview and applied a white image.but still its transparent. the background transparent view is set like this transprnt.backgroundColor = [UIColor darkTextColor]; transprnt.alpha = 0.800000011920929; [transprnt addSubview:whiteborderview]; – Midhun Raj Oct 09 '13 at 10:52
  • yes, that is causing all the subview transparent. for this make this view's alpha as 1. problem will be solved. – Imran Ahmed Oct 09 '13 at 10:56
  • i cant do that.the view should be transparent.its a requirment.i've specified dat earlier and yes its working fine when transparency is set to 1 . btw do u knw how to change the font color of datepicker? – Midhun Raj Oct 09 '13 at 11:08
  • http://stackoverflow.com/questions/18807940/can-i-change-the-font-color-of-the-datepicker-in-ios7 check this link. and for transparent view. you should add view1 with transparency on parent view. then add another view on parent without transparency which have uipickerview.it will work for you . and please make answer as correct if it works – Imran Ahmed Oct 09 '13 at 11:36
  • no it didnt work. i've mentioned the same link in my question too.while debugging its got getting into that function. what should i do?:( – Midhun Raj Oct 09 '13 at 11:45
2
[UIView appearanceWhenContainedIn:[UITableView class], [UIDatePicker class], nil].backgroundColor =[UIColor colorWithWhite:1 alpha:0];
pickerView.backgroundColor=[UIColor whiteColor];
anotherView.backgroundColor=[UIColor whiteColor];//Another view on which you subview picker