UINavigationBar - Change Height / Add Big Button - ios

I need to change the height of my Navigation Bar and add a custom Image button to the top left corner. I am part way there, but lost now on getting the custom Image button in the right position. Here is what I have:
To adjust the height I have created a UINavBar category with one method as follows:
#implementation UINavigationBar (myNavBar)
- (CGSize)sizeThatFits:(CGSize)size {
CGSize newSize = CGSizeMake(768,80);
return newSize;
}
#end
I have also created a UINavigationController subclass to modify the button. Here is the viewDidLoad from that class:
UIImage *navBackgroundImage = [UIImage imageNamed:#"bar"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
// Change the appearance of back button
UIImage *backButtonImage = [[UIImage imageNamed:#"back_off"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 6)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
// Change the appearance of other navigation button
UIImage *barButtonImage = [[UIImage imageNamed:#"menu_off"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
[[UIBarButtonItem appearance] setBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
So far this solution resizes the top nav bar, but positions my button in a weird position. Here are what I want vs. what is happening:
What I want
What I get

I have a UIBarButtonItem Category that I use which has an offset property:
UIBarButtonItem+CustomImage.h
#interface UIBarButtonItem (CustomImage)
+ (UIBarButtonItem*)barItemWithImage:(UIImage*)image target:(id)target action:(SEL)action offset:(CGPoint)offset;
#end
UIBarButtonItem+CustomImage.m
#import "UIBarButtonItem+CustomImage.h"
#implementation UIBarButtonItem (CustomImage)
+ (UIBarButtonItem *)barItemWithImage:(UIImage *)image target:(id)target action:(SEL)action offset:(CGPoint)offset {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
[button setFrame:CGRectMake(0.0, 0.0, image.size.width, image.size.height)];
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
[button setBounds:CGRectOffset(button.bounds, 0.0, -10.0)];
UIView *container = [[UIView alloc] initWithFrame:button.frame];
[container setBounds:CGRectOffset(container.bounds, offset.x, offset.y)];
[container addSubview:button];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:container];
return item;
}
#end
Example Usage
#import "UIBarButtonItem+CustomImage.h"
UIBarButtonItem *settingsButton = [UIBarButtonItem barItemWithImage:settingsImage
target:self
action:#selector(revealSettings:)
offset:CGPointMake(0.0, 0.0)];
[self.navigationItem setLeftBarButtonItem:settingsButton];

Related

Adding left and right UIBarButtonItem in navigation bar

I'm trying to create a standard navigation bar programmatically using UINavigationItem setLeftBarButtonItem and setRightBarButtonItem
I want to have NavigationItem that looks like
[ < BACKTEXT FWDTEXT > ]
I want to have a constant space between my images (arrow) and device edges.
I would also want to have a constant space between images and texts.
I created a category over UIBarButtonItem and added two method backButtonWith and fwdButtonWith
I read #Split useful answer that explained how to solve the right button
button.titleEdgeInsets = UIEdgeInsetsMake(0, - button.imageView.frame.size.width, 0, button.imageView.frame.size.width);
button.imageEdgeInsets = UIEdgeInsetsMake(0, button.titleLabel.frame.size.width, 0, -button.titleLabel.frame.size.width);
But I'm having a hard time resolving the back button.
Here is my code
- (UIBarButtonItem *)buttonWith:(BOOL) directionLeft title:(NSString *)title image:(UIImage *) buttonImage tintColor:(UIColor *)color target:(id)target andAction:(SEL)action{
UIButton *barButton;
barButton = [UIButton buttonWithType:UIButtonTypeCustom];
float buttonWidth = 130.0f;
[barButton setFrame:CGRectMake(0, 0, buttonWidth, 20.5f)];
[barButton setTitle:title forState:UIControlStateNormal];
[barButton setTitleColor:color forState:UIControlStateNormal];
const CGFloat* components = CGColorGetComponents(color.CGColor);
[barButton setTitleColor:[UIColor colorWithRed:components[0] green:components[1] blue:components[2] alpha:0.3f] forState:UIControlStateHighlighted];
UIEdgeInsets titleEdgeInsets;
UIEdgeInsets imageEdgeInsets;
UIImage *image = [self image:buttonImage tintedWithColor:color fraction:0.0];
[barButton setImage:image forState:UIControlStateNormal];
[barButton setImage:[self image:image byApplyingAlpha:0.3] forState:UIControlStateHighlighted];
[barButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
if(directionLeft == YES){
titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);//THIS PARAMS SHOULD BE CONFIGURED
imageEdgeInsets = UIEdgeInsetsMake(0,0,0,0);
}else{
titleEdgeInsets = UIEdgeInsetsMake(0, -barButton.imageView.frame.size.width, 0, barButton.imageView.frame.size.width);
imageEdgeInsets = UIEdgeInsetsMake(0, barButton.titleLabel.frame.size.width, 0, -barButton.titleLabel.frame.size.width);
}
barButton.imageEdgeInsets = imageEdgeInsets;
barButton.titleEdgeInsets = titleEdgeInsets;
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:barButton];
return barButtonItem;
}
The back button which you set to UINavigationItem appears on the next navigation item which is pushed to the navigation bar. You won't see in on the current navigation item. Also, as I remember, back button is not able to contain custom view, it should be plain UIBarButtonItem.
You can customize the appearance of your back button with
[UIBarButtonItem appearanceWhenContainedIn:<YourNavigationBar.class>]
or with general appearance
[UIBarButtonItem appearance]
For details on back button item appearance customization, please check out this question

Change the background color of a UIBarButtonItem in ios 7

I have a UINavigationBar with a right UIBarButtonItem.
How do I change just the background color of the button (not the text)?
UIBarButtonItem *postButton = [[UIBarButtonItem alloc] initWithTitle:#"POST" style:UIBarButtonItemStylePlain target:self action:#selector(postButtonPressed:)];
// Changes text color
postButton.tintColor = [UIColor blueColor];
How do I make the background color change?
Using storyboard or XIB, You could add UIButton directly to a navigation bar and change UIButton background color.
Use appearance proxy for this,
Create a 1x1 pixel image with the color you prefer. In this case this image's name is "icons_gb.png". Then add following code to your AppDelegate.m . Image color will be repeated in the button's background.
UIImage *btnBg = [[UIImage imageNamed:#"icons_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIBarButtonItem appearance] setBackgroundImage:btnBg
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
you can change it by:
yourNavigationBar.barTintColor = [UIColor yellowColor];
The color of navigation bar also be changed.
If you want to change only UIBarButtonItem, use my custom class:
UIBarButtonItem+Custom.h
#import <UIKit/UIKit.h>
#interface UIBarButtonItem (Custom)
+ (UIBarButtonItem *) barItemWithImage:(UIImage *)img size:(CGSize)size target:(id)target action:(SEL)selector;
#end
UIBarButtonItem+Custom.m
#import "UIBarButtonItem+Custom.h"
#implementation UIBarButtonItem (Custom)
+ (UIBarButtonItem *) barItemWithImage:(UIImage *)img size:(CGSize)size target:(id)target action:(SEL)selector
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:img forState:UIControlStateNormal];
button.frame= CGRectMake(0.0, 0.0, size.width, size.height);
[button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *forward = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
return forward;
}
#end

Custom UIBarButtonItem

I am trying to create a custom UIBarbuttonItem that uses just a png with transparency so that I only have an icon as button. When I try to set the button image, set the background as white, and set the style to Plain I still get an inner shadow and black border around it.
What gives?
I have tried the below code and it still puts the black border around it.
UIImage *background = [UIImage imageNamed:#"Dismiss_normal.png"];
UIImage *backgroundSelected = [UIImage imageNamed:#"Dismiss_selected.png"];
self.closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.closeButton addTarget:self action:#selector(closeButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; //adding action
[self.closeButton setBackgroundImage:background forState:UIControlStateNormal];
[self.closeButton setBackgroundImage:backgroundSelected forState:UIControlStateSelected];
self.closeButton.frame = CGRectMake(0 ,0,background.size.width, background.size.height);
self.closeButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.closeButton];
self.navigationItem.leftBarButtonItem = self.closeButtonItem;
What I noticed is if I do a modal segue the button, with the code above still has a black border around it, but if I do a push segue it doesn't? WTF?
You must set the button type to Custom and the icon image to the button background.
example code:
UIImage *background = [UIImage imageNamed:#"icon.png"];
UIImage *backgroundSelected = [UIImage imageNamed:#"icon_selected.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:#selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside]; //adding action
[button setBackgroundImage:background forState:UIControlStateNormal];
[button setBackgroundImage:backgroundSelected forState:UIControlStateSelected];
button.frame = CGRectMake(0 ,0,35,35);
Then set this button to your BarButtonItem like this:
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = barButton;
I understood your problem.
When you actually push a UIViewController it will be a part of existing UINavigationController. So the UINavigationBar retains. But when you use ModalViewController its just another UIViewController kind of "added" to your existing UIViewController. So the UINavigationBar won't be there.
But you can add another UINavigationBar from xib and add a UIButton. But don't directly add the UIButton, if you do so it will automatically convert to UIBarButton making it bordered.
So first drag a normal UIButton to your UIView(not navigation bar). Change it to custom and add UIImage to it using Attribute Inspector. Then drag that image to your custom created UINavigationBar. It will work as I tried it just now. You can see the screen shot attached below.
This will update ALL back buttons and navigation bars throughout the app.
I have used the Following code to set Custom Navigation back button
UIImage *imgBack = [[UIImage imageNamed:#"nav_back.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(-6, 22, -6, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:imgBack forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
and the Following code for Setting background image on navigation bar.
UIImage *navBackgroundImage = [UIImage imageNamed:#"nav_bar.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
Try use [UIBarButtonItem initWithCustomView]
UIImage *menuButtonImage = [UIImage imageNamed:#"list.png"];// set your image Name here
UIButton *btnToggle = [UIButton buttonWithType:UIButtonTypeCustom];
[btnToggle setImage:menuButtonImage forState:UIControlStateNormal];
btnToggle.frame = CGRectMake(0, 0, menuButtonImage.size.width, menuButtonImage.size.height);
UIBarButtonItem *menuBarButton = [[UIBarButtonItem alloc] initWithCustomView:btnToggle];
self.navigationItem.leftBarButtonItem = menuBarButton;
I personally like FlatUIKit's approach by just flattening out the entire UI through UIAppearance
Essentially, you'd do something like:
UIImage *backButtonPortraitImage = [UIImage backButtonImageWithColor:color barMetrics:UIBarMetricsDefault cornerRadius:cornerRadius];
UIImage *highlightedBackButtonPortraitImage = [UIImage backButtonImageWithColor:highlightedColor barMetrics:UIBarMetricsDefault cornerRadius:cornerRadius];
[appearance setBackButtonBackgroundImage:backButtonPortraitImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[appearance setBackButtonBackgroundImage:highlightedBackButtonPortraitImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
UIImage *buttonImageNormal = [UIImage imageWithColor:color cornerRadius:cornerRadius];
UIImage *buttonImageHightlighted = [UIImage imageWithColor:highlightedColor cornerRadius:cornerRadius];
[appearance setBackgroundImage:buttonImageNormal forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[appearance setBackgroundImage:buttonImageHightlighted forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
Try this code..
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *btnImage = [UIImage imageNamed:#"bg"];
[button setImage:btnImage forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, btnImage.size.width, btnImage.size.height);
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
UIImage *icon = [UIImage imageNamed:#"icon"]
UIImageView *iconView = [[UIImageView alloc] initWithImage:icon];
iconView.frame = CGRectMake(0, 0, icon.size.width, icon.size.height);
[button addSubview:iconView];
iconView..userInteractionEnabled=NO;
[iconView centerBothDirections];
[iconView release];
UIBarButtonItem *barbtn = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
self.navigationItem.leftBarButtonItem =barbtn

iPhone UINavigationBar - Set width and margin of rightBarButtonItem

I have a background image for a button, with the dimensions of 80x30 pixels.
I use the code below to set the background in my view-controller, and the result is this:
As you can see, the corners and the top of the right button is messed up.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIImage *favoriteBtnImgNormal = [[UIImage imageNamed:#"favorite-btn-normal"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 30, 0)];
UIImage *favoriteBtnImgTouch = [[UIImage imageNamed:#"favorite-btn-touch"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 30, 0)];
[self.navigationItem.rightBarButtonItem setBackgroundImage:favoriteBtnImgNormal forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self.navigationItem.rightBarButtonItem setBackgroundImage:favoriteBtnImgTouch forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
[self.navigationItem.rightBarButtonItem setBackgroundImage:favoriteBtnImgTouch forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[self.navigationItem.rightBarButtonItem setTitlePositionAdjustment:UIOffsetMake(-10.0, 0.0) forBarMetrics:UIBarMetricsDefault];
}
Note that I do this in a single view-controller, I use the appearance API to set general styles. But here I want to override the general appearance.
If I just get the images without the resizable-stuff, it looks like this:
Now the edges and corners are fine, but the button is too large.
I'm sure I'm doing this all wrong, so I need someone to point out what I could do to scale buttons correctly?
UIImage *image = [UIImage imageNamed:#"YourImage"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );
[button setImage:image forState:UIControlStateNormal];
[button addTarget:self action:#selector(YourAction) forControlEvents:UIControlEventTouchUpInside];
button.contentEdgeInsets = (UIEdgeInsets){.right=-10};
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];

UIBarButtonItem with custom image and no border

I want to create a UIBarButtonItem with a custom image, but I don't want the border that iPhone adds, as my Image has a special border.
It's the same as the back button but a forward button.
This App is for an inHouse project, so I don't care if Apple reject or approves it or likes it :-)
If I use the initWithCustomView:v property of the UIBarButtonItem, I can do it:
UIImage *image = [UIImage imageNamed:#"right.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage: [image stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateNormal];
[button setBackgroundImage: [[UIImage imageNamed: #"right_clicked.png"] stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateHighlighted];
button.frame= CGRectMake(0.0, 0.0, image.size.width, image.size.height);
[button addTarget:self action:#selector(AcceptData) forControlEvents:UIControlEventTouchUpInside];
UIView *v=[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, image.size.width, image.size.height) ];
[v addSubview:button];
UIBarButtonItem *forward = [[UIBarButtonItem alloc] initWithCustomView:v];
self.navigationItem.rightBarButtonItem= forward;
[v release];
[image release];
This works, but if I have to repeat this process in 10 views, this is not DRY.
I suppose I have to subclass, but what ?
NSView ?
UIBarButtonItem ?
thanks,
regards,
Another simple solution is
Drag a standard UIButton
Set the button's style to custom and set your image for that button
Drag it onto the UINavigationBar
Set Selector
You can add a method to UIBarButtonItem without subclassing it using custom category:
#interface UIBarButtonItem(MyCategory)
+ (UIBarButtonItem*)barItemWithImage:(UIImage*)image target:(id)target action:(SEL)action;
#end
#implementation UIBarButtonItem(MyCategory)
+ (UIBarButtonItem*)barItemWithImage:(UIImage*)image target:(id)target action:(SEL)action{
// Move your item creation code here
}
#end
So anywhere in your code you can create bar item calling this method (provided that you include a header with its declaration).
P.S. You do not need to use 'v' UIView as you can create UIBarButtonItem with a button as custom view directly.
P.P.S. You also need [forward release] in your code.
I found it this ways easy. It is sugested on top. "random.png" has to be in project. Just drag and drop any image.
UIButton *a1 = [UIButton buttonWithType:UIButtonTypeCustom];
[a1 setFrame:CGRectMake(0.0f, 0.0f, 25.0f, 25.0f)];
[a1 addTarget:self action:#selector(randomMsg) forControlEvents:UIControlEventTouchUpInside];
[a1 setImage:[UIImage imageNamed:#"config.png"] forState:UIControlStateNormal];
UIBarButtonItem *random = [[UIBarButtonItem alloc] initWithCustomView:a1];
//? line incomplete ?// imageNamed:#"random.png"] style:UIBarButtonItemStylePlain target:self action:#selector(randomMsg)];
self.navigationItem.rightBarButtonItem = random;
An alternative is to subclass UIBarButtonItem. Why? So that the action is invoked on the target with the correct sender. In the code above, the sender argument in the action message is the UIButton instance, not the UIBarButtonItem instance. This would be important, for example, if you wish to present a UIPopoverController from the bar button item. By subclassing UIBarButtonItem, you can add an ivar that retains the original target, allowing our subclass instances to intercept, modify, and forward the action message with the proper sender.
So, CCFBarButtonItem.h:
#import <uIKit/UIBarButtonItem.h>
#interface CCFBarButtonItem : UIBarButtonItem
{
#protected
id _originalTarget;
}
- (id)initWithImage:(UIImage *)image target:(id)target action:(SEL)action;
#end
and CCFBarButtonItem.m
#import "CCFBarButtonItem.h"
#import <UIKit/UIButton.h>
#import <UIKit/UIView.h>
#import <UIKit/UIImage.h>
#implementation CCFBarButtonItem
#pragma mark - Object life cycle
- (id)initWithImage:(UIImage *)image target:(id)target action:(SEL)action;
{
_ASSIGN( _originalTarget, target );
UIButton *imgButton = [UIButton buttonWithType:UIButtonTypeCustom];
[imgButton setImage:image forState:UIControlStateNormal];
imgButton.frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
[imgButton addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
self = [super initWithCustomView:imgButton];
return self;
}
- (void)dealloc;
{
MCRelease(_originalTarget);
[super dealloc];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
{
if( [_originalTarget respondsToSelector:aSelector] )
{
return [_originalTarget methodSignatureForSelector:aSelector];
}
else
{
return [super methodSignatureForSelector:aSelector];
}
}
- (void)forwardInvocation:(NSInvocation *)anInvocation;
{
SEL aSelector = [anInvocation selector];
if( [_originalTarget respondsToSelector:aSelector] )
{
// modify the 'sender' argument so that it points to self
[anInvocation setArgument:&self atIndex:2];
[anInvocation invokeWithTarget:_originalTarget];
}
else
{
[self doesNotRecognizeSelector:aSelector];
}
}
#end
UIBarButtonItem *menuItem = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed:#"icon-menu.png"]
style:UIBarButtonItemStylePlain
target:self
action:#selector(showMenu)];
This can also be done programmatically as well (of-course):
First, create a custom view. This custom view can contain an image, button or whatever else you would like. The custom view can be made programmatically or in IB:
UIImage *customImage = [UIImage imageNamed:#"imageName"];
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, customImage.size.width, customImage.size.height)];
customView.backgroundColor = [UIColor colorWithPatternImage:customImage];
Next, create a UIBarButtonItem and initialize it with the custom view.
UIBarButtonItem *customBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:customView];
Now, just add the custom UIBarButton to the leftBarButtonItem:
self.navigationItem.leftBarButtonItem = customBarButtonItem;
Ok that category works very good because there are no problems with Popovercontroller :-)
#import <UIKit/UIKit.h>
#interface UIBarButtonItem (BarButtonItemExtended)
+ (UIBarButtonItem*)barItemWithImage:(UIImage*)image target:(id)target action:(SEL)action;
-(void)performBarButtonAction:(id)sender;
#end
#import "UIBarButtonItem+BarButtonItemExtended.h"
#implementation UIBarButtonItem (BarButtonItemExtended)
+ (UIBarButtonItem*)barItemWithImage:(UIImage*)image target:(id)target action:(SEL)action
{
UIButton *imgButton = [UIButton buttonWithType:UIButtonTypeCustom];
[imgButton setImage:image forState:UIControlStateNormal];
imgButton.frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
UIBarButtonItem *b = [[UIBarButtonItem alloc]initWithCustomView:imgButton];
[imgButton addTarget:b action:#selector(performBarButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[b setAction:action];
[b setTarget:target];
return b;
}
-(void)performBarButtonAction:(UIButton*)sender
{
[[self target] performSelector:self.action withObject:self];
}
#end
One another solution, think it's simpler in case when creating button programatically:
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithImage:defaultImage
landscapeImagePhone:landscapeImage
style:UIBarButtonItemStylePlain
target:self
action:#selector(someSelector)];
[button setBackgroundImage:[UIImage new] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[button setBackgroundImage:[UIImage new] forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
Check this out simple solution.
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.image = [UIImage imageNamed:#"navButton.png"];
barButtonItem.style = UIBarButtonItemStylePlain;
[barButtonItem setBackgroundImage:[UIImage imageNamed:#"1x1.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.masterPopoverController = popoverController;
}
Here 1x1.png is a 1 pixel transparent png image which you can download from the link below
http://commons.wikimedia.org/wiki/File:1x1.png

Resources