Custom navigation and navigationitem
From http://www.codeios.com/thread-97-1-1.html
# Import "navtest. H"
@ Implementation uinavigationbar (mimimage)
// Define the navigation background image
-(Void) drawrect :( cgrect) rect {
Uiimage * image = [uiimage imagenamed: @ "bg.png"];
[Image drawinrect: cgrectmake (0, 0, self. Frame. Size. Width, self. Frame. Size. Height)];
}
@ End
@ Implementation navtest
-(Void) leftaction :( ID) sender
{
Uialertview * Alert = [[uialertview alloc] initwithtitle: @ "warning" message: @ "click the button on the left"
Otherbuttontitles: Nil];
[Alert show];
[Alert release];
}
-(Void) rightaction :( ID) sender
{
Uialertview * Alert = [[uialertview alloc] initwithtitle: @ "warning" message: @ "click the button on the right"
Otherbuttontitles: Nil];
[Alert show];
[Alert release];
}
// Implement viewdidload to do additional setup after loading the view, typically from a nib.
-(Void) viewdidload {
Self. navigationitem. Title = @ "Custom ";
// Define the buttons on the left
Uibutton * leftbutton = [[uibutton alloc] initwithframe: cgrectmake (0, 0, 60, 40)];
[Leftbutton setimage: [uiimage imagenamed: @ "titlebgbutton.png"] forstate: uicontrolstatenormal];
[Leftbutton setimage: [uiimage imagenamed: @ "titlebgbutton1.png"] forstate: uicontrolstatehighlighted];
[Leftbutton addtarget: Self action: @ selector (leftaction :) forcontrolevents: uicontroleventtouchupinside];
Uibarbuttonitem * leftitem = [[uibarbuttonitem alloc] initwithcustomview: leftbutton];
[Leftbutton release];
// Define the button on the right
Uibutton * rightbutton = [[uibutton alloc] initwithframe: cgrectmake (0, 0, 60, 40)];
[Rightbutton setimage: [uiimage imagenamed: @ "titlebgbutton.png"] forstate: uicontrolstatenormal];
[Rightbutton setimage: [uiimage imagenamed: @ "titlebgbutton1.png"] forstate: uicontrolstatehighlighted];
[Rightbutton addtarget: Self action: @ selector (rightaction :) forcontrolevents: uicontroleventtouchupinside];
Uibarbuttonitem * rightitem = [[uibarbuttonitem alloc] initwithcustomview: rightbutton];
[Rightbutton release];
Self. navigationitem. leftbarbuttonitem = leftitem;
Self. navigationitem. rightbarbuttonitem = rightitem;
[Leftitem release];
[Rightitem release];
[Super viewdidload];
}