Skip to content

Instantly share code, notes, and snippets.

@yaakaito
Forked from tikitikipoo/gist:1812562
Created July 22, 2012 15:21
Show Gist options
  • Save yaakaito/3159976 to your computer and use it in GitHub Desktop.
Save yaakaito/3159976 to your computer and use it in GitHub Desktop.
UIBarButtonItemのtintColorはios5からなのでios4でも同様なことができるように
// 出所:http://wizard.st/blog/archives/156
//   :http://fredandrandall.com/blog/2011/03/31/how-to-change-the-color-of-a-uibarbuttonitem/
UIBarButtonItem *item = nil;
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
item = [[UIBarButtonItem alloc] initWithTitle:title
style:useStyle
target:self
action:@selector(toolBarButtonTapped:)];
[item setTintColor:[UIColor blackColor]];
} else {
UISegmentedControl *btn = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:title, nil]] autorelease];
btn.momentary = YES;
btn.segmentedControlStyle = UISegmentedControlStyleBar;
btn.tintColor = [UIColor blackColor];
[btn addTarget:self action:@selector(toolBarButtonTapped:) forControlEvents:UIControlEventValueChanged];
item = [[UIBarButtonItem alloc] initWithCustomView:btn];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment