tombenner / nui

Style iOS apps with a stylesheet, similar to CSS
MIT License
3.76k stars 461 forks source link

BarButton style is not applied in UINavigationController #156

Open trombini opened 11 years ago

trombini commented 11 years ago

If i create a UINavigationController programmatically, the style for the BarButton in not applied. However, the style gets applied if I add a NavigationBar with the InterfaceBuilder. The BarButtons should all be grey if the style is applied correctly.

image

What am I missing?

bdewater commented 10 years ago

I'm having the same problem. I've tried to add a UIBarButtonItem to the navigation bar like this:

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil];
[barButtonItem setStyle:UIBarButtonItemStyleBordered];
[barButtonItem setNuiClass:@"BarButton"];
self.navigationItem.rightBarButtonItem = barButtonItem;

This shows an add button with the default styling, which I can't seem to override. I've also tried adding a UIButton like this:

UIButton *barButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[barButton setTitle:@"Button" forState:UIControlStateNormal];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:barButton];
barButtonItem.style = UIBarButtonItemStyleBordered;
self.navigationItem.rightBarButtonItem = barButtonItem;

I'm looking at the demo project with RevealApp and the first thing I noticed is that you get a UINavigationButton class button (with an UIImageView background) from the Interface Builder, which turns out to be an Apple private subclass of UIButton.

Using the second piece of code, it turns out that the button is in the view hierarchy (including styling) but it's frame has a height and width of 0, which can be manually adjusted from Reveal. Setting the button type to something that has an image (like UIButtonTypeInfoDark) also forces the button to have a height/width, but I can't get it to work out of the box with just text.

Edit: turns out the first code sample is styled by adding [NUIRenderer renderBarButtonItem:barButtonItem]; (from #125 ) :)