Get global tint color from code

前端 未结 6 1162
眼角桃花
眼角桃花 2020-11-30 04:18

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.

6条回答
  •  伪装坚强ぢ
    2020-11-30 04:43

    Easy.

    Objective C:

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

    Swift:

    let tintColor = self.view.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.

    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.

提交回复
热议问题