Swift 5 - iOS14 - customize UIDatePicker

Viewed 530

I try to customize the UIDatePicker in iOS14 but I'm unfortunately unable to do this. I want to change the background and border color of the UIDatePicker.

Here is my code in my class:

fileprivate let picker: UIDatePicker = {
        let picker = UIDatePicker()
        picker.translatesAutoresizingMaskIntoConstraints = false
        picker.datePickerMode = .time
        picker.preferredDatePickerStyle = .inline
        picker.layer.borderWidth = 0
        picker.minuteInterval = 15
        picker.backgroundColor = .clear
        picker.overrideUserInterfaceStyle = .light
        return picker
    }()

I want to change the background color of the inner gray part of the UIDatePicker to white or in this example to clear.

enter image description here

As you can see, the gray part on the white background doesn't really look good.

On note: I use the UIDatePicker in a UITableViewCell.

I hope you guys can help me and maybe there is only 1 or 2 lines which are missing in my code. :)

Best regards and stay healthy! Roman

1 Answers

UIDatePicker is not really customizable.

Known workaround is to place a UILabel on top the picker and format the label how you want and update it for UIDatePicker's value changes

Related