How to make a UIBarButtonItem like this

狂风中的少年 提交于 2019-12-01 07:11:14

问题


How can I make a UIBarButtonItem like this:

I can't find it in the SystemItem values.

Thanks


回答1:


That's probably using something like:

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

I tried with:

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

but it seems like with a custom view the bordered style doesn't get applied.




回答2:


The Image button which you have called info button.It's an system button,

Use below to get it as your rightBarButtonItem

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

Here is the documentation link to UIButtonType




回答3:


Swift's version of @Jhaliya's answer for quick copy-paste:

let infoButton = UIButton(type: .InfoLight)

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

let infoBarButtonItem = UIBarButtonItem(customView: infoButton)

navigationItem.rightBarButtonItem = infoBarButtonItem


来源:https://stackoverflow.com/questions/6290230/how-to-make-a-uibarbuttonitem-like-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!