It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am really having a hard time creating a UIToolBar programmatically(no xib file). This is what I would like to create.
But till now, I feel I have not approached it in the right way. I have tried adding a barbuttonitem to it, but I cant create the effect as shown in the png. How should I go about it. Help needed.
Edit: I have added a bigger image
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlackOpaque];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:#"toolbar title" style:UIBarButtonItemStylePlain target:self action:#selector(onToolbarTapped:)];
NSArray *toolbarItems = [NSArray arrayWithObjects:spaceItem, customItem, spaceItem, nil];
[self setToolbarItems:toolbarItems animated:NO];
Create your toolbar with CGRECT to put it where you want
UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(x, y, width, height)];
You can customize it with background image, title, text color, background color, ...
Next create your button
UIBarButtonItem *theButton = [UIBarButtonItem alloc] initWithTitle:#"button title" style:UIBarButtonItemStylePlain target:self action:#selector(selector:)];
Add it to yout toolbar :
NSArray *buttons = [NSArray arrayWithObjects: theButton, nil];
[myToolbar setItems:buttons animated:NO]
add your toolbar to the current view
[self.view addSubview:mytoolbar]
Just typed not tested, hope it'll help
ToolBar and buttons have custom images
- (void)viewDidLoad {
[super viewDidLoad];
UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 44, 320, 44)];
[myToolbar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"toolbar_40.png"]] autorelease] atIndex:0];
UIBarButtonItem *barButtonDone = [self createImageButtonItemWithNoTitle:#"button_down.png" target:self action:#selector(closeMe:)];
UIBarButtonItem *barButtonShare = [self createImageButtonItemWithNoTitle:#"button_share.png" target:self action:#selector(actionShareButton:)];
UIBarButtonItem *barButtonFlexibleGap = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]autorelease];
myToolbar.items = [NSArray arrayWithObjects:barButtonDone,barButtonFlexibleGap,barButtonShare,nil];
[self.view addSubview:myToolbar];
[myToolbar release];
}
-(void)closeMe:(id)sender
{
NSLog(#"closeMe");
}
-(void)actionShareButton:(id)sender
{
NSLog(#"actionShareButton");
}
-(UIBarButtonItem *)createImageButtonItemWithNoTitle:(NSString *)imagePath target:(id)tgt action:(SEL)a
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonImage = [[UIImage imageNamed:#"button_slice.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:0];
UIImage *buttonPressedImage = [[UIImage imageNamed:#"button_slice_over.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:0];
CGRect buttonFrame = [button frame];
buttonFrame.size.width = 32;
buttonFrame.size.height = 32;
[button setFrame:buttonFrame];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 32, 32)];
imageView.image = [UIImage imageNamed:imagePath];
[button addSubview:imageView];
[imageView release];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:buttonPressedImage forState:UIControlStateHighlighted];
[button addTarget:tgt action:a forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
return [buttonItem autorelease];
}
These png files need to be added
toolbar_40.png for toolbar image
button_down.png for button image
button_share.png for button image
button_slice.png for button background
button_slice_over.png for button background (pressed)
UIToolbar *toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlackTranslucent;
toolbar.backgroundColor = [UIColor clearColor];
Then add a UIBarButtonItem to toolbar.
UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 44, 320, 44)];
myToolbar.barStyle = UIBarStyleBlack;
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
myLabel.text = #"Sperre aufheben";
myLabel.textColor = [UIColor whiteColor];
myLabel.textAlignment = UITextAlignmentCenter;
myLabel.backgroundColor = [UIColor clearColor];
[myToolbar addSubview:myLabel];
[self.view addSubview:myToolbar];
[myLabel release];
[myToolbar release];
Seems like a better fit for a nav bar (at least if you are keeping with the spirit of what you are doing: IE adding a title to the bottom of the screen)
Anyway I created a simple test project and this is what I did to get the functionality pictured, you may have to insert it into the view/controller differently but it gets what you want relatively easy and doesn't use the button bar
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 44, 320, 44)];
[navBar setBarStyle:UIBarStyleBlack];
UINavigationItem *title = [[UINavigationItem alloc] initWithTitle:#"Your Title"];
NSArray *array = [[NSArray alloc] initWithObjects:title, nil];
[navBar setItems:array];
[self.view addSubview:navBar];
}
Related
I want to insert one button and one label in my NavigationBar in iOS.
I have tried with UISegmentedControl and it works completely fine with one control!
Now the problem is I want to add multiple controls as i have said before How can I?
Look at my code
UIView *v;
[v insertSubview:listingsLabel atIndex:0];
[v insertSubview:shareBtn atIndex:1];
[v setFrame:[self.navigationController.toolbar bounds]];
self.navigationItem.titleView = v;
v.frame = CGRectMake(0, 0, 200, 29);
and it gives me error of EXC_BAD_ACCESS
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 44.01)];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard "add" button
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray array]];
[segmentedControl insertSegmentWithTitle:#"All" atIndex:0 animated:NO];
[segmentedControl insertSegmentWithTitle:#"Related" atIndex:1 animated:NO];
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[segmentedControl addTarget:self action:#selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
// create a standard "add" button
UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithCustomView: segmentedControl];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// create a spacer
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[buttons addObject:bi];
[bi release];
// create a standard "refresh" button
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:#selector(save:)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];
[buttons release];
// and put the toolbar in the nav bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
Because you don't init the UIView the right way, it crashes because the iPhone doesn't know what to do with
[v insertSubview:listingsLabel atIndex:0];
This is because v isn't an object yet. So change
UIView *v;
to
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 29)];
And release it here again (if not using arc)
self.navigationItem.titleView = v;
[v release];
The navigation bar on iPhone only supports only a left and right bar button item, and a title view. Only the (larger) navigation bar on iPad allows an arbitrary number of buttons.
If you're using a navigation bar without a navigation controller, I suppose you could just plop whatever you want onto it as subviews.
UIButton *btnBack = [[UIButton alloc]initWithFrame:CGRectMake(5,5,60,32)];
[btnBack setBackgroundImage:[UIImage imageNamed:#"back_btn.png"] forState:UIControlStateNormal];
btnBack.backgroundColor = [UIColor clearColor];
[btnBack addTarget:self action:#selector(eventBack:) forControlEvents:UIControlEventTouchUpInside];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(12, 2, 60,25)];
[lbl setBackgroundColor:[UIColor clearColor]];
lbl.font = [UIFont fontWithName:#"Helvetica" size:12];
lbl.font = [UIFont boldSystemFontOfSize:12];
lbl.textColor = [UIColor whiteColor];
lbl.text =#" Back";
[btnBack addSubview:lbl];
[lbl release];
UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
self.navigationItem.leftBarButtonItem = backBarBtn;
[btnBack release];
[backBarBtn release];
UILabel *lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(110, 0, 170, 40)];
lblTitle.text = #"ABC";
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.textColor = [UIColor whiteColor];
lblTitle.textAlignment = UITextAlignmentCenter;
lblTitle.font = [UIFont fontWithName:#"Helvetica" size:17];
lblTitle.font = [UIFont boldSystemFontOfSize:17];
self.navigationItem.titleView = lblTitle;
[lblTitle release];
How to Create multiple bar button in navigation bar?
From iOS 5 onwards, you can now do it using setLeftBarButtonItems:animated: or setRightBarButtonItems:animated:
You must use UIToolbar and set the toolbar with buttons:
// create a toolbar where we can place some buttons
UIToolbar *toolbar = [[UIToolbar alloc]
initWithFrame:CGRectMake(0, 0, 100, 45)];
[toolbar setBarStyle: UIBarStyleBlackOpaque];
// create an array for the buttons
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard save button
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self
action:#selector(saveAction:)];
saveButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:saveButton];
// create a spacer between the buttons
UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[buttons addObject:spacer];
// create a standard delete button with the trash icon
UIBarButtonItem *deleteButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemTrash
target:self
action:#selector(deleteAction:)];
deleteButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:deleteButton];
// put the buttons in the toolbar and release them
[toolbar setItems:buttons animated:NO];
// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
you have to create a view with as much button you required and have to add them on navigation button like following :
UIView *parentView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
UIButton *infoButton1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 6, 30, 32)];
[infoButton1 setBackgroundImage:[UIImage imageNamed: #"navbtn.png"] forState:UIControlStateNormal];
[infoButton1 setTitle:#"Back" forState:UIControlStateNormal];
infoButton1.titleLabel.font = [UIFont systemFontOfSize:13.0f];
infoButton1.titleLabel.textColor = [UIColor whiteColor];
[infoButton1 addTarget:self action:#selector(backBarButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[parentView1 addSubview:infoButton1];
[infoButton1 release];
UIButton *infoButton2 = [[UIButton alloc] initWithFrame:CGRectMake(30, 6, 30, 32)];
[infoButton2 setBackgroundImage:[UIImage imageNamed: #"navbtn.png"] forState:UIControlStateNormal];
[infoButton2 setTitle:#"Back" forState:UIControlStateNormal];
infoButton2.titleLabel.font = [UIFont systemFontOfSize:13.0f];
infoButton2.titleLabel.textColor = [UIColor whiteColor];
[infoButton2 addTarget:self action:#selector(backBarButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[parentView1 addSubview:infoButton2];
[infoButton2 release];
UIBarButtonItem *customBarButtomItem1 = [[UIBarButtonItem alloc] initWithCustomView:parentView1];
[parentView1 release];
self.navigationItem.leftBarButtonItem = customBarButtomItem1;
[customBarButtomItem1 release];`enter code here`
I know this question was already closed, but I find that the UIToolbar solution doesn't match visually.
If you instead use a second UINavigationBar set with a UINavigationItem that has a title of nil and the desired buttons you can add more buttons and have a bar that visually matches the original.
For iOS7 and higher, this is the right way to do it. No need for UIToolbar silliness.
- (void)viewDidLoad {
[super viewDidLoad];
[self configureView];
// create three funky nav bar buttons
UIBarButtonItem *one = [[UIBarButtonItem alloc]initWithTitle:#"One" style:UIBarButtonItemStylePlain target:self action:#selector(testMethod)];
UIBarButtonItem *two = [[UIBarButtonItem alloc]initWithTitle:#"Two" style:UIBarButtonItemStylePlain target:self action:#selector(testMethod)];
UIBarButtonItem *three = [[UIBarButtonItem alloc]initWithTitle:#"Three" style:UIBarButtonItemStylePlain target:self action:#selector(testMethod)];
// create a spacer
UIBarButtonItem *space = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
space.width = 30;
NSArray *buttons = #[one, space, two, space, three];
self.navigationItem.rightBarButtonItems = buttons;
}
I hate putting links as answers on SO as they can die anytime so i added relevant code taken from HERE
- (void)viewWillAppear
{
// get a view and :
[self.navigationController.navigationBar addSubView:yourView];
}
read the following code:
// Creiamo la toolbar sotto
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 372, 320, 44)];
toolbar.tintColor = [UIColor blackColor];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"imgImpostazioniToolbar.png"]];
UIBarButtonItem *pulsanteImpostazioni = [[UIBarButtonItem alloc] initWithCustomView:imageView];
[pulsanteImpostazioni setTarget:self];
[pulsanteImpostazioni setAction:#selector(prova)];
[imageView release];
UIBarButtonItem *spaziatore = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
NSArray *buttons = [[NSArray alloc] initWithObjects:spaziatore, pulsanteImpostazioni, spaziatore, nil];
[toolbar setItems:buttons animated:NO];
[self.view addSubview:toolbar];
[buttons release];
I can see correctly my image but when I try to touch it nothing happen.
I didn't set correctly the selector of "pulsanteImpostazioni"?
Thanks
P.s. "prova" contain only a NSLog.
Try
[pulsanteImpostazioni setAction:#selector(prova:)];
The colon at the end of the selector name matters.
i find the solution in this mode:
UIButton *pulsanteImpostazioni = [UIButton buttonWithType:UIButtonTypeCustom];
[pulsanteImpostazioni setFrame:CGRectMake(0, 0, 200, 50)];
[pulsanteImpostazioni setImage:[UIImage imageNamed:#"imgImpostazioniToolbar.png"] forState:UIControlStateNormal];
[pulsanteImpostazioni addTarget:self action:#selector(prova) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *pulsanteImpostazioni = [[UIBarButtonItem alloc] initWithCustomView:pulsanteImpostazioni];
Thanks anyway for your answers =)
i got the following code:
- (id)init {
if (self = [super init]) {
self.title = #"please wait";
UIBarButtonItem *favorite = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"star.png"] style:UIBarButtonItemStylePlain target:self action:#selector(buttonFavoriteClicked:)];
self.navigationItem.rightBarButtonItem = favorite;
}
return self;
}
but my button looks still like a Button with UIBarButtonItemStyleBordered
is there a way to set a button with plain style at this position?
Create a UIButton in interface builder, make it look like exactly what you want. Create an outlet for in in your .h:
IBOutlet UIButton * _myButton;
Then set it as your right bar button item using a custom view, which will eliminate the border:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_myButton];
This works because UIButton is a subclass of UIView.
Try this instead:
- (id)init {
if (self = [super init]) {
self.title = #"please wait";
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
[button setImage:[UIImage imageNamed:#"star.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonFavoriteClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *favorite = [[UIBarButtonItem alloc] initWithCustomView:button];
[button release];
self.navigationItem.rightBarButtonItem = favorite;
}
return self;
}
Hope it helps.
Or do this in code without IB:
// add setting button to nav bar
UIImage* settingsGearImg = [UIImage imageNamed:#"settings_gear.png"];
CGRect frameimg = CGRectMake(0, 0, settingsGearImg.size.width, settingsGearImg.size.height);
UIButton *settingsButton = [[UIButton alloc] initWithFrame:frameimg];
[settingsButton setBackgroundImage:settingsGearImg forState:UIControlStateNormal];
[settingsButton addTarget:self action:#selector(settingsButtonAction) forControlEvents:UIControlEventTouchUpInside];
[settingsButton setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *settingButtonItem =[[UIBarButtonItem alloc] initWithCustomView:settingsButton];
self.navigationItem.leftBarButtonItem = settingButtonItem;
Results in:
When using this icon image (it's white on a white background so isn't visible here - link is: http://i.stack.imgur.com/lk5SB.png):
It's weird but it works. Say "No" to images/outlets! You shouldn't even set the UIBarButtonItemStylePlain property. The trick is to place button into UIToolBar with some special attributes:
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:#"Cool plain bar"];
UIToolbar *tools = [[UIToolbar alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, 44.0f, 44.01f)];
tools.clipsToBounds = NO;
tools.barStyle = -1; // clear background
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:1];
UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:#selector(refreshTableView)];
[buttons addObject:bi];
[tools setItems:buttons animated:NO];
UIBarButtonItem *rightButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];
item.rightBarButtonItem = rightButtons;
item.hidesBackButton = YES;
[myCoolNavigationBar pushNavigationItem:item animated:NO];
Although Frank is right, this code should be in viewDidLoad, the issue here is what BarButtons look like. If you want it to look different, you need to use a different type of UIView. You can add a UIButton to a UIToolbar just fine.
-(void)viewDidLoad {
[super viewDidLoad];
self.title = #"please wait";
self.navigationItem.rightBarButtonItem = [[[UIButton alloc] init] autorelease];
}
Edit:
Sorry, you wanted a plain UIBarButtonItem. I don't believe you can do this with a UINavigationBar. You could try adding a UserInteractionEnabled UILabel as the rightBarButtonItem, I'm not sure if it will work or not.
Seems this isn't currently possible.
sbwoodside has a solution.
Why not try UI7Kit? Works well for me, easy to use.
UIImage *img = [UIImage imageNamed:#"white_star.png"];
CGSize itemSize = CGSizeMake(20, 20);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[img drawInRect:imageRect];
img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIBarButtonItem *barButton = [[UIBarButtonItem alloc ] initWithImage:img style:UIBarButtonSystemItemAdd target:self action:#selector(favoriteButtonClicked)];
barButton.style = UIBarButtonItemStyleBordered;
Try this,
UIBarButtonItem *barBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"more.png"] style:UIBarButtonItemStylePlain target:self action:#selector(didPressButton)];
I'm trying to implement UINavigationBar with custom controls. So, I've added UIView on left side of UINavigationBar and trying to add controls to that UIView with following code:
UIView *view = navigationController.navigationItem.leftBarButtonItem.customView;
UIButton *button = [[UIButton alloc] initWithFrame:view.frame];
[button setTitle:#"TEST" forState:UIControlStateNormal];
[view addSubview:button];
[button sizeToFit];
[button release];
Code works, but button doesn't appear.
Any help would be appreciated.
Thank you.
UPD
OK, I gave a try to code below and made such thing:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 50)];
[button setTitle:#"XXX" forState:UIControlStateNormal];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:button];
navigationController.visibleViewController.navigationItem.leftBarButtonItem = customItem;
[customItem release];
[button release];
The "XXX" title did appear, but it looks like simple label, not button. Any ideas?
Yes, your UIButton doesn't come with any shading. What I've done is used a UISegmentedControl to get shading for free:
// Add the Menu button to the navigation bar
NSString* menuLabel = "ShadeButton";
CGSize textSize = [menuLabel sizeWithFont:[UIFont systemFontOfSize:15.0]];
UISegmentedControl* menuSegmentedButton = [[UISegmentedControl alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, textSize.width, 29.0f)];
menuSegmentedButton.momentary = YES;
menuSegmentedButton.selected = NO;
menuSegmentedButton.segmentedControlStyle = UISegmentedControlStyleBar;
[menuSegmentedButton insertSegmentWithTitle:menuLabel atIndex:0
animated:NO];
[menuSegmentedButton addTarget:self action:#selector(doMenu)
forControlEvents:UIControlEventValueChanged];
UIBarButtonItem* barButton = [[UIBarButtonItem alloc]
initWithCustomView:menuSegmentedButton];
[menuSegmentedButton release];
self.navigationItem.rightBarButtonItem = barButton;
Create your UIBarButtonItem with the UISegmentedControl as shown above rather than a UIButton and you should get the effect you're after. The alternative is to do more work on the button and create a texture/custom image for it yourself.
Note quite right.
If you just want a different title:
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:#"TEST" style:UIBarButtonItemStylePlain target:nil action:nil];
navigationController.navigationItem.leftBarButtonItem = customItem;
[customItem release];
If you really want a custom view:
// Create Custom View called myView.
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithCustomView:myView];
navigationController.navigationItem.leftBarButtonItem = customItem;
[customItem release];