当为 appDelegate 中的所有视图设置自定义 tintColor 时,更改特定视图的色调颜色

Change tint color for a specific view when custom tintColor is set for all views in appDelegate

我正在尝试通过故事板更改 segmentControl 上的 tintColor。但是,不幸的是,在我的 AppDelegate 中,我为我的应用程序中的所有视图设置了默认 tintColor

在 AppDelegate 中:

UIView.appearance().tintColor = .myCustomColor

这将始终覆盖我的所有其他更改。因此,例如,如果我通过故事板或以编程方式在我的 segmentControl 上设置另一个 tintColor,它不会有任何影响。是否可以在不删除我在 appDelegate 中的代码的情况下解决这个问题?

要设置全局色调颜色但仍允许在控件或视图中使用不同的色调,只需设置:

window?.tintColor = .myCustomColor

AppDelegateapplication(_:didFinishLaunchingWithOptions:)函数中。

要为所有 windows 设置色调颜色,您可以使用:

window?.tintColor = UIColor.gray