user635064
user635064

Reputation: 6247

How to make a UIBarButtonItem like this

How can I make a UIBarButtonItem like this: enter image description here

I can't find it in the SystemItem values.

Thanks

Upvotes: 3

Views: 6371

Answers (3)

mokagio
mokagio

Reputation: 17491

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

Upvotes: 1

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31730

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

Upvotes: 18

André Morujão
André Morujão

Reputation: 7153

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.

Upvotes: 7

Related Questions