Reputation: 3255
I am using following code to create a 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];
I add this and another button to a UIToolbar, not sure if that's relevant. This works fine and gives me the look I intended:
The problem is that with iOS 4 (which I have to support) I can't set the tintColor. Unrecognized Selector. How can I create such a button for iOS 4? I need to be able to set the tintColor and have UIBarButtonItemStyleBordered.
Thanks for your help.
I got it to work like this:
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];
You have to initialize it with one empty NSString, otherwise you can't set an image. Also the addTarget has to use UIControlEventValueChanged
Upvotes: 2
Views: 359
Reputation: 15213
You need to create an UIButton
and either draw the button to look like this by yourself or set a background image with this and initialize the UIBarButtonItem
with a custom view (your UIButton
).
P.S. From the release of iOS6 you can't compile to armv6 anymore and the lowest version you can support is 4.3, which according to me isn't worth it...
Upvotes: 1