问题
I'm trying to customize a UIBarButtonItem using the appearance method (>iOS 5.0). It works fine for the UIControlStateNormal, but not for highlighted or disabled. See images
Here's the code I use to set those:
// now configure the UIBarButtonItems
UIImage *buttonBGInactive = [[UIImage imageNamed:@"button-navbar-30-inactive.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
UIImage *buttonBGActive = [[UIImage imageNamed:@"button-navbar-30-pressed.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 15)];
[[UIBarButtonItem appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage: buttonBGInactive forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage: buttonBGActive forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
Any ideas? The images themselves are 30x30px and I'm not requiring landscape mode.
回答1:
I found the solution to the problem. My images are 30x30px and I set the resizable endcaps to
UIEdgeInsetsMake(0, 15, 0, 15)
by setting those 15's to 14's, the problem went away. So best not to make endcaps the exact half of the image width.
来源:https://stackoverflow.com/questions/12301555/setbackgroundimage-for-uibarbuttonitem-via-appearance-not-working-for-other-uico