快速更改默认全局色调颜色

快速更改默认全局色调颜色

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

问题描述

我正在开发一个小应用程序,我想将默认的全局色调颜色从蓝色更改为橙​​色.我已经在Objective-C中看到了许多方法来执行此操作,但是我似乎无法使用Swift使其正常工作.我怎样才能做到这一点?预先感谢!

I'm developing a little app and I would like to change the default global tint color from blue to orange. I've seen many ways to do it in Objective-C but I can't seem to get it to work using swift. How could I achieve this? Thanks in advance!

推荐答案

此答案最后一次针对Swift 5.2和iOS 13.5 SDK进行了修订.

您可以在窗口上设置 tintColor .由于色调颜色会向下级联到所有子视图(除非明确覆盖),因此将其设置在窗口上将有效地使其在该窗口内变为全局.

You can set the tintColor on your window. Because tint color cascades down to all subviews (unless explicitly overridden), setting it on a window will effectively make it global inside that window.

将以下行添加到您的 application(_:didFinishLaunchingWithOptions:) scene(_:willConnectTo:options:) :

Add the following line to your application(_:didFinishLaunchingWithOptions:) or scene(_:willConnectTo:options:) just before making the window key and visible:

window.tintColor = .systemOrange /* or .orange on iOS < 13 */

您还可以通过更改Global Tint属性在情节提要中进行设置:

You can also set in in the storyboard by changing the Global Tint property:

这篇关于快速更改默认全局色调颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:39