我使用以下代码创建 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
最佳答案
tintColor
已在 iOS5 中添加,适用于 iOS4 here你有一个解决方案
关于ios - UIBarButtonItem 色调颜色 iOS4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13375291/