Forum Xamarin.iOS

Style elements defined in Interface Builder are not being applied when instantiating from Storyboard

I have an iOS app developed in Xamarin.iOS (C#, Monotouch) where the primary UI is NOT storyboard-based. (I do this because my app needs structurally different layouts in portrait and landscape orientations, and it is a great deal easier to achieve that programmatically than through IB and Storyboarding.)

My problem is that I'm now trying to use a Storyboard to develop a simple dialog, but when I instantiate the dialog the structure is there but the style elements defined in Interface Builder are not being applied. Everything I've read seems to suggest that this should just happen. This is particularly problematic as most of the style elements cannot be modified after the interface is initialized.

Here's the code where I do the instantiation:

UIStoryboard sb = UIStoryboard.FromName("StoryboardAppSettings", null);
var vc = sb.InstantiateViewController("TableViewControllerAppSettings");
UIViewController settingsVC = vc as UIViewController;
PresentViewController(settingsVC, true, null);

I have defined a UITableView that is to be "grouped", but it isn't. I have two UISwitch elements with colors defined that are not being applied. I have buttons whose tint colors are not being applied.

(If I set a breakpoint and drill down into the view controller data structures, I find that all these parameters ARE set correctly...they just seem to be ignored when the hierarchy is realized.)

What am I doing wrong?


  • I found that the problem was that I was setting UIView.Appearance.BackgroundColor. It seems that when you do that, the UIView.Appearance.BackgroundColor ALWAYS overrides UISwitch.OnTintColor. (In my mind that is a bug, probably in iOS, but I may misunderstand how the Appearance API is supposed to work. My expectation is that a generalized global setting (like UIView.Appearance) can be overridden at more specific levels (descendent views or specific instantiations), and I believe that is the way it works for most other Appearance properties. UISwitch.OnTintColor (as well as UISwitch.TintColor and UISwitch.BackgroundColor, but NOT UISwitch.ThumbTintColor) seems to be the exception (and hence bug), not the rule.

Sign In or Register to comment.