iosswiftuidatepicker

How to change UIDatePicker tint color?


I am aware that UIDatePicker cannot be customized but I am wondering how in iOS 14 Reminders app shows blue tint and Calender shows red tint.

I set global tint color in AppDelegate to .label as below but unable to set the same for date picker.

UIView.appearance().tintColor = .label

Is this possible?

Another issue I have observed is in dark mode current date’s day number isn’t visible. How to solve this?

enter image description here


Solution

  • Reminders and Calendar have blue and red tint color (accent color) respectively.


    UIView.appearance().tintColor = .label works. However, the .label is white in darkmode and the text-color of today's date when selected is also white. Therefore, it looks so. Use another color than .label (white) to test it,

    You can not change the text color of today's date. It is always white, I think.

    You may not need to change the global tint color. If you only need to chagne the tintColor of the datepicker, do this:

    datepicker.tintColor = .yourColor does the job.

    If your global tint color is .label, use another color than .label as the tint-color of UIDatePicker to fix the issue.


    You can also change the global tint color using one of the following method.

    UIKit

    You need to change the tint color of the whole App to change the tint color of UIDatePicker.

        self.window?.tintColor = .primary // .red
    

    https://stephenradford.me/quick-tip-globally-changing-tint-color-application-wide/


    SwiftUI

    Change accentColor in Assets.


    Change global tint color - iOS7/iOS8