开发者

Custom "Done" button in Utility Application

开发者 https://www.devze.com 2023-01-15 00:41 出处:网络
Trying to get custom \"Done\" button in Utility Application Create new project in Xcode using Utility template

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

精彩评论

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