xcode 如何以编程方式更改全局色调颜色?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19641476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:12:38  来源:igfitidea点击:

How can I change the global tint color programmatically?

iosxcodestoryboarduistoryboardtint

提问by jimbob

My project needs to switch between 2 different global tint values. How can I do this programmatically?

我的项目需要在 2 个不同的全局色调值之间切换。我怎样才能以编程方式做到这一点?

回答by Leo Natan

Change the tint color of the UIWindowof the application. You can either use the [[UIApplication sharedApplication] keyWindow]but better is to use [[UIApplication sharedApplication] delegate].window.

更改UIWindow应用程序的色调颜色。您可以使用 ,[[UIApplication sharedApplication] keyWindow]但更好的是使用[[UIApplication sharedApplication] delegate].window.

回答by Gonzo

UIAppearanceis the answer! It sets property to all the objects of that class (and subclasses).

UIAppearance就是答案!它将属性设置为该类(和子类)的所有对象。

[[UIView appearance] setTintColor:(UIColor *)]

You can change the backgroudColorof all the buttons too

您也可以更改backgroudColor所有按钮的

[[UIButton appearance] setBackgroundColor:(UIColor *)]