Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add custom image in navigation bar button item?

 UIBarButtonItem *doneitem=[[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)]autorelease];     self.navigationItem.rightBarButtonItem=doneitem; 

This is the code of my app, I need to add a image on this button ?

Please help me.

like image 842
M Faheem Rajput Avatar asked May 09 '11 07:05

M Faheem Rajput


2 Answers

Try this code:

UIImage* image3 = [UIImage imageNamed:@"mail-48_24.png"]; CGRect frameimg = CGRectMake(0, 0, image3.size.width, image3.size.height); UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg]; [someButton setBackgroundImage:image3 forState:UIControlStateNormal]; [someButton addTarget:self action:@selector(sendmail)      forControlEvents:UIControlEventTouchUpInside]; [someButton setShowsTouchWhenHighlighted:YES];  UIBarButtonItem *mailbutton =[[UIBarButtonItem alloc] initWithCustomView:someButton]; self.navigationItem.rightBarButtonItem=mailbutton; [someButton release]; 
like image 154
Aman Aggarwal Avatar answered Sep 20 '22 15:09

Aman Aggarwal


 UIBarButtonItem *_btn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"XXXXXXX.png"]                                                    style:UIBarButtonItemStylePlain                                                    target:self                                                    action:@selector(yourMethod)];  self.navigationItem.rightBarButtonItem=_btn; 
like image 27
Gurpreet Singh Avatar answered Sep 21 '22 15:09

Gurpreet Singh