2012-02-13 105 views
-1

UINavigationBar是RedColour。如何为BarButton添加背景颜色

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"Hello" style:UIBarButtonItemStylePlain target:self action:@selector(bbPressed:)]; 

self.navigationItem.rightBarButtonItem=barButton ; 

现在我需要给上面的BarButton一个黑色的背景颜色。我如何以编程方式执行此操作?

我试过这个使用IB和它的作品,但我需要使用代码只。

步骤如何在IB中完成;

将背景颜色更改为RED。 更改样式为 - BlackTranslucent

我试着设置这些使用的代码,但它不起作用。

帮助

+0

检查 http://stackoverflow.com/questions/664930/uibarbuttonitem-with-color – Martin 2012-02-13 14:10:19

回答

0

你不能改变的UIBarButton默认样式。使用[[UIBarButtonItem alloc] initWithCustomView:yourView]其中yourView是定制的UIButton

+0

你能告诉我一个例子? – shajem 2012-02-13 14:06:49

+0

你可以查看这个链接:http://www.switchonthecode.com/tutorials/iphone-tutorial-how-to-create-a-blue-navigation-button – 2012-02-13 14:13:54