When do UIAppearance proxy rules get applied to new view controller?

坚强是说给别人听的谎言 提交于 2019-12-08 14:58:26

问题


I'm wandering when exactly do UIAppearance rules get applied to some new view controller?

I've made some global rules and I call them in my app delegate. That way all UIButtons look that same. But now I want to modify just appearance of one UIButton. I've tried putting the code to remove it's background inside - (void)viewDidLoad but it's not working - UIAppearance rules aren't applied yet. In one ViewController I put modification code inside - (void)viewWillLayoutSubviews and it worked perfectly, but now in another ViewController it doesn't work (code is the same).

Where is it safe to override UIAppearance rules?


回答1:


According to the 2011 WWDC video introducing UIAppearance, the customizations are applied right before -layoutSubviews is called on the view.




回答2:


If you're looking to customise one specific button you should either:

  1. Alter the properties of the button instance directly, and not touch the appearance settings for the class, or

  2. Use the appearanceWhenContainedIn: method like below:

    [[UIButton appearanceWhenContainedIn:[CustomView class], nil]
     setBackgroundImage:myButtonImage
                forState:UIControlStateNormal];
    

That way you can still use the appearance proxy for your specific button (when you know it's contained in a specific view), and not alter the general appearance settings.



来源:https://stackoverflow.com/questions/11471362/when-do-uiappearance-proxy-rules-get-applied-to-new-view-controller

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!