繁体   English   中英

UIBarButtonItem tintColor iOS4

[英]UIBarButtonItem tintColor iOS4

我正在使用以下代码创建 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,不确定这是否相关。 这很好用,并给了我我想要的外观:

UIButtonBarItem 截图

问题是,在 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

tintColor是在 iOS5 中添加的,对于 iOS4 在这里你有一个解决方案

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

PS 从 iOS6 发布开始,您不能再编译到 armv6,并且您可以支持的最低版本是 4.3,据我所知,这不值得...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM