【问题标题】:Create a UIBarButtonSystemItem with UIBarButtonItemStyle使用 UIBarButtonItemStyle 创建一个 UIBarButtonSystemItem
【发布时间】:2011-09-08 16:11:01
【问题描述】:

我想创建一个系统 UIBarButton,但我希望它具有简单的样式。
我已经尝试过使用此代码,但样式被忽略了。 它有什么问题?

UIBarButtonItem *search = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(showSearch)];    
search.style = UIBarButtonItemStylePlain;
self.navigationItem.rightBarButtonItem = search;
[search release];

【问题讨论】:

  • search.style = UIBarButtonItemStylePlain; 是不必要的,因为UIBarButtonItemStylePlain 是此类的样式属性的默认值。来自UIBarButtonItem_Class
  • 我添加它以尝试删除边框。文档说普通样式是默认样式,但在我的情况下并非如此。系统按钮有边框。

标签: iphone ios uinavigationbar uibarbuttonitem uibarbuttonitemstyle


【解决方案1】:

这里的主要内容是您需要将按钮放在前一个控制器中,而不是在将要按下的控制器中。

//Your actual ViewController
UIBarButtonItem *search = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(showSearch)];    
search.style = UIBarButtonItemStylePlain;
self.navigationItem.rightBarButtonItem = search;
[search release];

//Controller that is going to be pushed and will display the new UIBarButtonItem
[self.navigationController pushViewController:newViewController animated:YES];

【讨论】:

    【解决方案2】:

    找到了一个类似的帖子here

    似乎制定此计划的方法是创建自定义 UIButton 并将其分配给条形按钮。

    【讨论】:

    • 使用 UIButton 我失去了系统按钮的优势,即避免创建自己的图像。
    • 我明白了。如果不在代码上尝试,我无法验证这一点,但我想知道这是否可能是这里的问题 - >也许系统按钮默认带有自己的边框样式。如果我有时间会研究一下。
    • 我最终创建了一个图像。不是我想要的,但它似乎是唯一的解决方案。
    • 我自己一直在寻找解决方案...不想重新创建标准按钮图像。还没有...
    猜你喜欢
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    相关资源
    最近更新 更多