I’ve been playing around with developing a custom iOS component and have stumbled upon something very strange. What lead me here was the idea that my component should have the same look and feel as the standard components provided by the iOS APIs.
So here I was coding along and testing things out and I wanted to add a UIToolbar:
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, 30.0)];
Very straight forward. But when I fired this up in the simulator the bar was tinted blue, not like the light gray that is showing for the other bars (UINavigationBars, specifically) that I’m using already and that I want to mimic. Ok, let me try with a UINavigationBar, since I’m using those already:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, 32.0)];
Blue again…WTF? Now at this point a reasonable person would say something to the effect of “Screw this, I’ll just set the tintColor myself!”, and that’s what I did. But I was unable to get the color set to the right values to duplicate the default colors provided. I was close, but there’s no reason I shouldn’t be able to outright copy it. Now I’ve got to know what’s going on.
After spending a fair amount of time trying to figure out what the default tintColor values are (in a default state tintColor = nil, so I couldn’t just look at an existing component) and failing I started seeing what was different between the default UINavigationBar that I was already using and the one I was creating. Well the obvious difference was the height, default is 44, I was setting it to 30. So I set it to 44:
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, frame.size.width, 44.0)];
DING! It’s the light gray tint that I wanted, but why? Well, I don’t know, I did more poking around and could find zero mention of a correlation of the height of the components and their default tint color. So that’s why I’m writing this, so at least there’s some mention of this. Perhaps someone will pick up on this and point out something obvious that I’m missing, we’ll see.
I did more poking around and found that if the height is 32 or less, then it was blue, if greater that 32 (well, technically, greater than 32.000001) then it was light gray. The only reason I could think of this being a Good Idea™ is that 32 is the default height for the bars on the iPhone. But then this tintColor change should be tied to what device it’s actually running on, not some arbitrary height value.
I have every intent of searching RADAR and filing a report, but as it is I can’t seem to login, so I filed a bug report for the bug reporting system, of course. I’ll update this post if I found out more info.