nui icon indicating copy to clipboard operation
nui copied to clipboard

BarButton style is not applied in UINavigationController

Open trombini opened this issue 11 years ago • 1 comments

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?

trombini avatar Aug 23 '13 06:08 trombini

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 ) :)

bdewater avatar Jan 02 '14 14:01 bdewater