UIButton
カスタム イメージを使用して を作成し、UIBarButtonItem
カスタムUIButton
ビューとして を 使用して を作成します。
UIImage *buttonImage = [UIImage imageNamed:@"image"]; // Tint this image programmatically
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
これは主に iOS 6 以下用であることに注意してください。iOS 7 以降では、この動作を無料で取得できますtintColor
。