Iphone iOS 6外观API UIBarButtonSystemItemAdd不工作?

Iphone iOS 6外观API UIBarButtonSystemItemAdd不工作?,iphone,objective-c,ios,Iphone,Objective C,Ios,在iOS 6中,您可以访问外观API中的新方法: - (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state style:(UIBarButtonItemStyle)style barMetrics:(UIBarMetrics)barMetrics 因此,您可以为每个导航按钮样式设置不同的背景。问题是

在iOS 6中,您可以访问外观API中的新方法:

- (void)setBackgroundImage:(UIImage *)backgroundImage
              forState:(UIControlState)state
                 style:(UIBarButtonItemStyle)style
            barMetrics:(UIBarMetrics)barMetrics
因此,您可以为每个导航按钮样式设置不同的背景。问题是,它似乎不适用于
uibarbuttonsystemadd
样式,但它适用于
uibarbuttonimstyledone
。以下是我的代码片段:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0f)
{
    // Works well
    [barButton setBackgroundImage:[[UIImage imageNamed:@"nav-button-done.png"] stretchableImageWithLeftCapWidth:7 topCapHeight:0]
                         forState:UIControlStateNormal
                            style:UIBarButtonItemStyleDone
                       barMetrics:UIBarMetricsDefault];

    // Not working
    [barButton setBackgroundImage:[[UIImage imageNamed:@"nav-button-done.png"] stretchableImageWithLeftCapWidth:7 topCapHeight:0]
                         forState:UIControlStateNormal
                            style:UIBarButtonSystemItemAdd
                       barMetrics:UIBarMetricsDefault];
}

有人知道它为什么不起作用吗?

注意uibarbuttonite的方法声明:

- (void)setBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state style:(UIBarButtonItemStyle)style barMetrics:(UIBarMetrics)barMetrics
问题是UIBarButtonSystemItemAdd不是有效的UIBarButtonItemStyle。支持的样式包括:

typedef enum {
    UIBarButtonItemStylePlain,
    UIBarButtonItemStyleBordered,
    UIBarButtonItemStyleDone,
} UIBarButtonItemStyle;

您将UIBarButtonItemStyle与UIBarButtonSystemItem混为一谈,它们实际上并不相同,只是忽略了您在其上的设置值,并恢复为默认类型。

哦,明白了,所以没有简单的方法可以轻松地将添加按钮(带加号的按钮)与UIApparence一起锁定?不,这是一个SystemItem按钮,其要点是,您可以获得统一的系统外观。您可以创建一个看起来像它的按钮,但它必须是某种自定义按钮。没那么难,只是多做了点工作:)谢谢你的解释!