Changing colours of a UIToolbar + it's buttons when presented in a Popover Controller on the ipad
On both the iPhone and the iPad I have a need to present two buttons on the right hand side of a nav开发者_开发知识库igation bar. I'm doing this with the following snippet of code:
UIToolbar *rightBarButtons = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 92, 44.01)];
UIBarButtonItem *send = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(send)];
[send setStyle:UIBarButtonItemStyleBordered];
UIBarButtonItem *add = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(addRecipe:)];
[add setStyle:UIBarButtonItemStyleBordered];
NSArray *buttons = [[NSArray alloc] initWithObjects:send,add,nil];
[send release];
[add release];
[rightBarButtons setItems:buttons];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBarButtons];
[buttons release];
[rightBarButtons release];
On the iPhone the colours are fine, and in landscape mode on the iPad it is fine as they are grey. However in portrait mode the view appears inside a popover controller which has a dark black/blue colour. My buttons and the toolbar show up as the default grey.
How can I make the toolbar buttons match? If you do not use the hack above and just present one button as normal the colour change is handled and I guess I just need to implement that colour change manually, problem is, I can't seem to get the colour to change at all.
This would appear to be a property called barStyle and not tintColor as I previously thought. The simplest solution is to copy the bar style from elsewhere:
[rightBarButtons setBarStyle:self.navigationController.navigationBar.barStyle];
It's then fairly trivial to ensure the style remains correct as the view changes. Although I have to say I quite liked the dark blue black buttons over the silver navigation bar that gave after rotation.
精彩评论