Custom navigation color right button iPhone

Source: Internet
Author: User

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];

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.