Changing all UIView Background color using appearance API

AfshinDavaluAfshinDavalu USMember
edited July 2015 in Xamarin.iOS

I am trying to use the appearance api to change the theme of my app. It works with all the controls that I tried except UIView. Whenever I try to assign a color to it using 'UIView.Appearance.BackgroundColor = UI.Black;' It applies that property to all the sub controls, resulting in a black screen once the app loads.
I have tried creating a sub class of UIView and using it in the storyboard, then once I assign a background color to it I get the same behavior
Any advice will be helpful, Thanks in advance

Best Answer

Answers

  • adamkempadamkemp mod USInsider, Developer Group Leader mod

    That is a really terrible idea for the reason you just found. What the appearance API does is set the default value for that property for all views of that type. But UIView is the base class for every view so you're changing the default background color for every single thing in the app that doesn't explicitly have a background color set. There are a lot of views that are created just for layout purposes, and those usually have the default transparent background so that they're not visible. You just made them visible and black. Obviously you don't want that.

    So what are you actually trying to do?

  • AfshinDavaluAfshinDavalu USMember

    Briefly, I`m trying to implement a functionality of a Day/Night Theme. Each them will have a different background color in almost all of the screens. The appearance API works well with customizing all the other controls, But what would be the best way to do the same to the background color of the storyboards?

Sign In or Register to comment.