本文介绍了如何更改 UIDatePicker 色调颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 UIDatePicker 无法自定义,但我想知道如何在 iOS 14 提醒应用程序中显示蓝色调,而日历显示红色调.

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.

我将 AppDelegate 中的全局色调颜色设置为 .label 如下,但无法为日期选择器设置相同的颜色.

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

UIView.appearance().tintColor = .label

这可能吗?

我观察到的另一个问题是在黑暗模式下当前日期的天数不可见.如何解决这个问题?

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

推荐答案

RemindersCalendar 分别具有蓝色和红色色调(强调色).

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

UIView.appearance().tintColor = .label 有效.但是, .label 是暗模式中的白色,选择的日期的文本颜色也是白色的.因此,它看起来如此.使用除 .label(白色)以外的其他颜色来测试,

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 do more because you can not change the text color of today's date. It is always white, I think.

您可能不需要更改全局色调颜色,datepicker.tintColor = .yourColor 即可.

You may not need to change the global tint color, datepicker.tintColor = .yourColor does the job.

如果您的全局色调是 .label,请使用除 .label 之外的其他颜色作为 UIDatePicker 的色调来解决问题.

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.

要改变UIDatePicker的tint color,需要改变整个App的tint color.

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

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

  • scene(_:willConnectTo:options:)中,使用上面的代码

    如果不使用SceneDelegate,请使用上面application(_:didFinishLaunchingWithOptions:)

    If you do not use SceneDelegate, use the code above in application(_:didFinishLaunchingWithOptions:)

    您也可以在 Storyboard 中更改它.

    You can also change it in Storyboard.

    https://stephenradford.me/quick-提示全局更改色调颜色应用程序范围/

    更改资产中的accentColor.

    更改全局色调 - iOS7/iOS8

    这篇关于如何更改 UIDatePicker 色调颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 17:55