locked
Getting Global Tint RRS feed

  • Question

  • User389953 posted

    Hi

    I'm trying to get the Global Tint color from within a small UIButton subclass. I seem to have to do it differently at run-time and to support the designer. I wrote an extension method for UIView as below (so far only tested in a UIButton descendent)

    public static UIColor GetGlobalTint(this UIView thisView) { var keyWindow = UIApplication.SharedApplication.KeyWindow; if (keyWindow != null) { // this works for the designer return keyWindow.RootViewController.View.TintColor; } else { // this works at run time return thisView.TintColor; } }

    This seems to work consistently in designer and simulator. But I'm not sure why. It's just outside my understanding :-)

    I wonder if anyone can take a stab at explaining why this is needed?

    Many thanks

    Thursday, October 24, 2019 9:38 AM

All replies

  • User369978 posted

    Do you mean the first condition if (keyWindow != null) always true?

    Thursday, October 24, 2019 2:12 PM
  • User389953 posted

    No, I don't understand why UIApplication.SharedApplication.KeyWindow is null at run time, but not in the designer. Somehow it would seem more likely the other way round?

    Thursday, October 24, 2019 2:43 PM