I've got a UINavigationController and i've changed it to white using the Tint property of the navigation bar in Interface Builder. But the text in buttons and the title is still the default color, white, and so gets lost against the white background. Anyone know how to work around this?
Can't you iterate the contents of the UINavigationBar view to find the buttons in the awakeFromNib?
Here's one way:
[[theNavigationBar.subviews objectAtIndex:1] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[[theNavigationBar.subviews objectAtIndex:2] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
However, HUGE, caveat. This is highly likely to break on a future OS release and is not recommended.
At the very least you should perform a lot of testing and make sure you your assumptions of the subview layout of the navigation bar are correct.
I did as drunknbass suggested. I resorted to making a series of images for back-button in a few states, and regular buttons in a few states, and put them in a custom UIButton subclass, setting up the appropriate styles.
As a solution it doesn't scale particularly well, but my needs were simple enough. It has the advantage of not breaking if the subview orders in the built in controls change though, which is the obvious downside of that approach. Disadvantage of needing several images. The other tricky thing is handling an orientation change, since the buttons should change size.
On a related note, if you do change the tint color of your navigation bar, it does not play well with the special "More" view controller for customizing the order of a tab bar. There doesn't seem to be any "acceptable" way to change the color of the toolbar in that view.
Hi,
I want to change the width of the navigation default button. I have a big Title for my navigation bar but i want my default back button to be small. how do i do it??
Thanks in advance.
Here the clean way (relying on public API) to do this IMHO : you should use the titleView
property of the navigationItem
to apply it your own UILabel
on which you will customize the textColor
UILabel* lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
lbl.textAlignment=UITextAlignmentCenter;
lbl.backgroundColor=[UIColor clearColor];
lbl.textColor=[UIColor colorWithRed:0.18 green:0.2 blue:0.56 alpha:1];
theControllerOnWhichYouWantToHaveATitleWithYourOwnColor.navigationItem.titleView=lbl;
[lbl release];
for (id subView in theNavigationBar.subviews) {
if ([subView isKindOfClass:[UIButton class]]) {
[(UIButton *)subView setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[(UIButton *)subView setTitleShadowColor:[UIColor clearColor] forState:UIControlStateNormal];
}
}