实用程序中的自定义“完成”按钮

时间:2010-09-08 04:55:53

标签: iphone

尝试在Utility Application

中获取自定义“完成”按钮
  1. 使用工具模板
  2. 在Xcode中创建新项目
  3. 将图片done_button.png放入项目
  4. 在viewDidLoad方法的FlipsideViewController.m中添加一些代码。我在导航控制器中更改按钮时成功使用此代码。
  5.     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.hidesBackButton=YES;
        [barButtonItem_back release];
    

    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.hidesBackButton=YES; [barButtonItem_back release];

    1. 我只能看到标准的完成按钮,而不是自定义。如果我在xib中删除此按钮 - 我根本看不到任何按钮。
    2. 我想我无法访问这里的项目 - self.navigationItem.leftBarButtonItem = barButtonItem_back;

      plz帮助 SERG

1 个答案:

答案 0 :(得分:0)

解决!

  1. 为UINavigationItem添加一个出口UINavigationItem * navigItem到FlipsideViewController.h。
  2. 打开FlipsideView.xib并连接插座。
  3. 分配按钮

    navigItem.leftBarButtonItem = barButtonItem_back;