从代码中获取全局色调

从代码中获取全局色调

本文介绍了从代码中获取全局色调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过代码从我的项目中获取全局色调?为了避免误解,我的意思是全局色调颜色,我可以在文件检查器中设置.

Is there a way I can get the global tint color from my project by code? To avoid a misunderstanding I mean the global tint color, which i can set in the File Inspector.

推荐答案

简单.

目标 C:

UIColor *tintColor = [[self view]tintColor];

斯威夫特:

let tintColor = self.view.tintColor;

这应该会在应用程序上设置 tintColor.如果你改变它,这个属性应该得到更新.这假设您在一个 viewController 或一个的子类中,并且您没有在此视图和窗口之间的某个 superView 中覆盖 tintColor .

This should get the tintColor set on the app. If you change it, this property should get updated. This assumes you're inside a viewController or a subclass of one and that you haven't overridden the tintColor in some superView between this view and the window.

更新:请注意,如果您尝试获取尚未添加到窗口中的视图控制器的色调颜色,那么它将没有自定义色调颜色,因为该颜色是从窗口对象.感谢@ManuelWa 在评论中指出这一点.

Update: Notice if you are attempting to get the tint color of a view controller that has not been added to the window then it will not have the custom tint color since this color is inherited from the window object. Thanx to @ManuelWa for pointing this out in the comments.

这篇关于从代码中获取全局色调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:26