按下控制器时,UIBarButtonItemStyleDone不会在导航栏中创建蓝色按钮 [英] UIBarButtonItemStyleDone does not create blue buttons in navigation bar when controller is pushed

查看:52
本文介绍了按下控制器时,UIBarButtonItemStyleDone不会在导航栏中创建蓝色按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在几个不同的论坛上进行了搜索,似乎找不到答案.我向导航控制器添加了一个条形按钮项,并将其样式设置为UIBarButtonItemStyleDone.当这是导航堆栈上的第一个控制器时,该按钮将正确显示为蓝色.但是,当创建控制器并将其压入堆栈时,样式将被忽略,并显示为黑色.

I've searched around on several different forums and can't seem to find an answer for this. I have added a bar button item to a navigation controller and set its style to UIBarButtonItemStyleDone. When this is the first controller on the navigation stack, the button properly shows up blue. However, when the controller is created and pushed onto the stack, the style is ignored and it shows up black.

我知道更改tintColor时会发生此问题,但是我使用的是标准UIBarStyleBlack而不设置tintColor.我也尝试将tintColor设置为nil,但这也不起作用.

I know that this problem occurs when the tintColor has been changed, but I am using the standard UIBarStyleBlack and not setting tintColor. I've tried setting tintColor to nil, as well, but that doesn't work either.

相关代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.navigationItem.rightBarButtonItem =
    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                                  target:self
                                                  action:@selector(createNew:)];
    self.navigationItem.rightBarButtonItem.style = UIBarButtonItemStyleDone;
}

任何想法或解决方法将不胜感激.

Any ideas or workarounds would be greatly appreciated.

推荐答案

您正在使用预设的系统项目,为此 style 属性不执行任何操作.您需要切换到实际的 UIBarButtonSystemItemDone 系统项(蓝色,但显示完成"),或切换到使用 -initWithImage:style:target:action: -initWithTitle:style:target:action:并提供您自己的图像或文本.

You're using a preset system item, for which the style property does nothing. You need to either switch to the actual UIBarButtonSystemItemDone system item (which is blue, but says "Done"), or switch to using either -initWithImage:style:target:action: or -initWithTitle:style:target:action: and supplying your own image or text.

这篇关于按下控制器时,UIBarButtonItemStyleDone不会在导航栏中创建蓝色按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆