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.
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];
UIBarButtonItem *_btn=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"XXXXXXX.png"] style:UIBarButtonItemStylePlain target:self action:@selector(yourMethod)]; self.navigationItem.rightBarButtonItem=_btn;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With