【问题标题】:UIBarButtonItem tintColor iOS4UIBarButtonItem tintColor iOS4
【发布时间】:2012-11-02 17:46:32
【问题描述】:

我正在使用以下代码来创建 UIBarButtonItem:

UIBarButtonItem* searchBarButton = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"search_picto"] style:UIBarButtonItemStyleBordered target:self action:@selector(actionSearch:)] autorelease];
searchBarButton.tintColor = [UIColor colorWithRed:0.27 green:0.60 blue:0.20 alpha:1.00];

我将这个和另一个按钮添加到 UIToolbar,不确定这是否相关。 这很好用,给了我想要的外观:

问题是使用 iOS 4(我必须支持)我无法设置 tintColor。无法识别的选择器。如何为 iOS 4 创建这样的按钮?我需要能够设置 tintColor 并拥有 UIBarButtonItemStyleBordered。

感谢您的帮助。


我让它像这样工作:

UISegmentedControl* searchButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"", nil]];
[searchButton setImage:[UIImage imageNamed:@"search_picto"] forSegmentAtIndex:0];
searchButton.momentary = YES;
searchButton.segmentedControlStyle = UISegmentedControlStyleBar;
searchButton.tintColor = [DELEGATE.config getColor:IFXShopConfigScopeShop name:@"navigationTint"];
[searchButton addTarget:self action:@selector(actionSearch:) forControlEvents:UIControlEventValueChanged];

你必须用一个空的 NSString 来初始化它,否则你不能设置一个图像。 addTarget 也必须使用UIControlEventValueChanged

【问题讨论】:

    标签: ios cocoa-touch ios4


    【解决方案1】:

    您需要创建一个UIButton 并自己绘制按钮使其看起来像这样,或者使用它设置背景图像并使用自定义视图(您的UIButton)初始化UIBarButtonItem

    附:从 iOS6 版本开始,您无法再编译为 armv6,您可以支持的最低版本是 4.3,在我看来这不值得...

    【讨论】:

      【解决方案2】:

      tintColor是在iOS5中添加的,对于iOS4here你有解决办法

      【讨论】:

      • 我昨天看了这个,看来还是对的。
      猜你喜欢
      • 1970-01-01
      • 2011-08-15
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多