开发者

Custom "Done" button in Utility Application

Trying to get custom "Done" button in Utility Application

  1. Create new project in Xcode using Utility template
  2. Put image done_button.png in project
  3. 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];

  1. 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!

  1. Add an outlet UINavigationItem *navigItem to FlipsideViewController.h for the UINavigationItem.
  2. Open the FlipsideView.xib and connect the outlet.
  3. Assign button

    navigItem.leftBarButtonItem = barButtonItem_back;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜