且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从代码中获取全局色调

更新时间:2023-01-28 09:26:08

简单.

目标 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.