Search code examples
iosuidatepicker

UIDatePicker does not show everything


Here is My Image.... image

The UIDatePicker seems to not show everything on the screen. Any solutions on making the font size smaller?


Solution

  • According to Apple doc, I guess we cannot.

    You cannot customize the appearance of date pickers.

    A workaround is you can customize a UIPickerView work as a date picker and then change the font size by using UIPickerViewDelegate something like:

        func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
            var label: UILabel
    
            if let view = view as? UILabel {
                label = view
            } else {
                label = UILabel()
            }
    
            label.textColor = .black
            label.textAlignment = .center
            label.font = UIFont.systemFont(ofSize: 30)
    
            label.text = recheckDayOptions[row].toString()
    
            return label
        }