2009-10-28 59 views
0

我必须在导航栏的右侧有两个按钮。所以我创建了一个工具栏并在其内容视图中添加了两个栏按钮项目。如下所示。navigationItem.rightBarButtonItem需要两个按钮。图像没有显示

UIBarButtonItem *shareButton = [[UIBarButtonItem alloc] 
            initWithImage:[UIImage imageNamed:@"share-icon-32x32.png"] 
            style:UIBarButtonItemStyleBordered 
            target:self action:@selector(showShare)]; 

    shareButton.width = 30.0f; 
    [buttons addObject:shareButton]; 
    [shareButton release]; 

其中buttons是一个数组,其中包含按钮对象。

一样聪明,我有像下面

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] 
             initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
             target:self 
             action:@selector(addDescription)]; 

     addButton.style = UIBarButtonItemStyleBordered; 
     [buttons addObject:addButton]; 
     [addButton release]; 

数组现在添加到工具栏像下面

[toolbar setItems:buttons animated:YES]; 
    [buttons release]; 

,并将其添加到rightBarButton像另一个barbutton项目下

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] 
               initWithCustomView:toolbar]; 
    [toolbar release]; 

我在右栏上显示两个栏按钮项目,但我无法显示图片分享按钮项目上。它只是一个白色的补丁。任何机构都可以告诉我我做错了什么或如何显示图像。

问候,

赛优素福

回答

1

从文档为initWithImage:style:target:action:

的α值在源图像中用于创建图像不透明值是 忽略。

这意味着UIKit使用图像的Alpha通道,而不是RGB像素值。您提供的图像可能完全不透明(没有透明度),initWithImage:style:target:action:将其解释为白色正方形。您必须使用定义图标形状的Alpha通道保存图像。

+0

嗨贝格曼, 非常感谢。是的,我使用的是不透明的图像。我使用了等效的灰度图像,它确实显示在导航栏中。 Regards, Syed Yusuf – 2009-10-30 17:32:04

+0

如果您觉得它回答了问题,请将答案标记为已接受。 – 2009-10-30 18:19:03