UIBarButtonItem的setBackgroundImage通过外观不适用于其他UIControlStates

我试图使用外观方法(> iOS 5.0)自定义UIBarButtonItem。 它工作正常的UIControlStateNormal,但不是突出显示或禁用。 看图像

在默认状态下,请注意右边的禁用状态

突出显示状态也不起作用

这是我用来设置这些的代码:

// 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]; 

有任何想法吗? 图像本身是30x30px,我不需要横向模式。

我find了解决问题的办法。 我的图像是30x30px,我设置可resize的endcaps

UIEdgeInsetsMake(0,15,0,15)

通过设置15岁到14岁,问题就消失了。 所以最好不要使图像宽度的确切一半。