ios - UIBarButtonItem 色调颜色 iOS4

标签 ios cocoa-touch 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 中,不确定这是否相关。 这工作正常,给了我我想要的外观:

screenshot of 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 here你有一个解决方案

关于ios - UIBarButtonItem 色调颜色 iOS4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13375291/

相关文章:

ios - xcodebuild 不会编译项目,除非它至少使用 Xcode 打开一次,用于 cocoapods 集成项目

ios - 当键盘出现时滚动到 UIScrollView 的最底部(AutoLayout)

ios - 模拟器而非iPhone上的iOS SQLite Mach-O错误(4)

ios - Swift NSCoding 中的 EXC_BAD_INSTRUCTION

ios - 右键单击MenuIcon

iPhone:在设置导航栏显示/隐藏动画时无法设置 contentInset 动画

iphone - ios4模拟器上的照片库路径

iOS 媒体库 : React to Access Apple Music Alert

iphone - CLLocationCoordinate2D 制作行为

iphone - 如何以编程方式完全像这个 UIButton 布局?