如何制作像这样的UIBarButtonItem

时间:2011-06-09 08:47:32

标签: objective-c cocoa-touch ios uibarbuttonitem

如何制作如下的UIBarButtonItem: enter image description here

我在SystemItem值中找不到它。

由于

3 个答案:

答案 0 :(得分:18)

您已调用信息按钮的图像按钮。这是一个系统按钮,

使用以下内容将其作为 rightBarButtonItem

UIButton* myInfoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[myInfoButton addTarget:self action:@selector(InfoButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myInfoButton];

以下是UIButtonType

的文档链接

答案 1 :(得分:7)

这可能是使用类似的东西:

[[UIBarButtonItem alloc] initWithImage:@"info.png" style:UIBarButtonItemStyleBordered target:nil action:nil]

我尝试过:

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]];
item.style = UIBarButtonItemStyleBordered;

但似乎在自定义视图中,无法应用镶边样式。

答案 2 :(得分:1)

Swift的版本@Jhaliya快速复制粘贴的答案:

let infoButton = UIButton(type: .InfoLight)

infoButton.addTarget(self, action: "InfoButtonClicked:", forControlEvents: .TouchUpInside)

let infoBarButtonItem = UIBarButtonItem(customView: infoButton)

navigationItem.rightBarButtonItem = infoBarButtonItem