Trying to get custom "Done" button in Utility Application
- Create new project in Xcode using Utility template
- Put image done_button.png in project
- Add some code in FlipsideViewController.m in viewDidLoad method. I use this code successfully when change buttons in navigation controllers.
UIImage *back_image=[UIImage imageNamed:@"done_button.png"];
UIButton *back_button = [UIButton buttonWithType:UIButtonTypeCustom];
back_button.bounds = CGRectMake( 0, 0, back_image.size.width, back_image.size.height);
[back_button setBackgroundImage:back_image forState:UIControlStateNormal];
[back_button addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem_back = [[UIBarButtonItem alloc] initWithCustomView:back_button];
self.navigationItem.leftBarButtonItem = barButtonItem_back;
self.navigationItem.hide开发者_运维问答sBackButton=YES;
[barButtonItem_back release];
- I can see standard Done button only, not custom. If I delete this button in xib - I can't see any buttons at all.
I think I cant get access to items here - self.navigationItem.leftBarButtonItem = barButtonItem_back;
plz help Serg
Solved!
- Add an outlet UINavigationItem *navigItem to FlipsideViewController.h for the UINavigationItem.
- Open the FlipsideView.xib and connect the outlet.
Assign button
navigItem.leftBarButtonItem = barButtonItem_back;
精彩评论