Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 禁用位于UINavigationBarItem的系统映像周围的边框_Iphone_Uinavigationcontroller_Uibutton - Fatal编程技术网

Iphone 禁用位于UINavigationBarItem的系统映像周围的边框

Iphone 禁用位于UINavigationBarItem的系统映像周围的边框,iphone,uinavigationcontroller,uibutton,Iphone,Uinavigationcontroller,Uibutton,我想禁用iPhone SDK的添加按钮周围的边框,所以它只是“+”按钮(没有黑色背景): 当它位于工具栏中时,这似乎是一项简单的任务,但当它位于UINavigationBar中时,则不是。不管怎样,如果有人知道怎么做,或者这是可能的,那么请分享!这是我的RootViewController.m中的当前代码: self.title = @"Code Master"; addButton = [[UIBarButtonItem alloc] initWithBarB

我想禁用iPhone SDK的添加按钮周围的边框,所以它只是“+”按钮(没有黑色背景):

当它位于工具栏中时,这似乎是一项简单的任务,但当它位于UINavigationBar中时,则不是。不管怎样,如果有人知道怎么做,或者这是可能的,那么请分享!这是我的RootViewController.m中的当前代码:

self.title = @"Code Master";
addButton = [[UIBarButtonItem alloc]
                initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                target:self action:@selector(addButtonClicked:)];
self.navigationItem.rightBarButtonItem = addButton; 

编辑

@所以你的代码工作得很好,显示的正是我想要的!现在我要解释的是另一个问题:

编辑按钮:UINavigationBar左侧
完成按钮:UINavigationBar左侧(隐藏);单击“编辑”按钮时,它将用此“完成”按钮替换“编辑”按钮
加号按钮:导航栏右侧;在“编辑模式”下隐藏,在“正常模式”下显示(当“完成”按钮不可见时)

所以基本上我现在的问题是,每当我点击编辑,然后点击完成,加号按钮不会从隐藏中返回。我使用的是你的确切代码,它与我以前的代码一起工作。我很确定这是因为在你的代码中,没有任何东西将其标记为“addButton”。以下是稍后在我的主文件中的代码:

-(void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:YES];
    if (editing)
    {
        self.navigationItem.rightBarButtonItem = nil;
    }
    else
    {
          UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
          [button setImage:[UIImage imageNamed:@"Plus.png"] forState:UIControlStateNormal];
          [button addTarget:self action:@selector(addButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
          [button setFrame:CGRectMake(0, 0, 50, 29)];
          UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:button];
          self.navigationItem.rightBarButtonItem = barBtn;
          [barBtn release];
    }

    [self.tableView reloadData];
}
创建“+”图像并将其设置为button&将该按钮交给UIBarButtonItem,如下所示:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"Plus.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(addButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 50, 29)];
UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setRightBarButtonItem:barBtn];
[barBtn release];

因为您将其设置为nil,所以它不会再次出现。尝试在else部分中添加相同的代码。编辑了你的代码。看一看。