Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - UIDatePicker background color

enter image description hereMy UIDatePicker's background is black (because the background for the whole screen is black probably), but I want white in the background for this UIDatePicker.

Is there any way to change the background color without subclassing it?

like image 887
Rocky Avatar asked Mar 15 '13 23:03

Rocky


3 Answers

datePickerName.backgroundColor = [UIColor grayColor];
like image 147
Ramdhas Avatar answered Sep 21 '22 05:09

Ramdhas


iOS 14 update

It looks that datePicker.backgroundColor doesn't work in iOS 14. It works. But you have to put it after preferredDatePickerStyle setting:

let picker = UIDatePicker()
if #available(iOS 13.4, *) {
    picker.preferredDatePickerStyle = .wheels
}
picker.backgroundColor = .red
like image 28
goodliving Avatar answered Sep 23 '22 05:09

goodliving


OBJECTIVE C

datePicker.backgroundColor = [UIColor greenColor]

SWIFT

DatePicker.backgroundColor = UIColor.blueColor()
DatePicker.setValue(UIColor.greenColor(), forKeyPath: "textColor")
DatePicker.setValue(0.8, forKeyPath: "alpha")
like image 32
Dishant Rajput Avatar answered Sep 23 '22 05:09

Dishant Rajput