【发布时间】: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