Ham Dong Kyun
Ham Dong Kyun

Reputation: 776

How to implement image and text for bar button item

The iPhone's default calendar program shows the "<" and text at the same time in the navigator bar.

I want to have image and text simultaneously as well.

How is this implemented in Xcode?

enter image description here

Upvotes: 0

Views: 2443

Answers (2)

shtefane
shtefane

Reputation: 454

Create a custom button

UIButton *barBt =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
[barBt setImage:[UIImage imageNamed:@"my_image.png"] forState:UIControlStateNormal];
[barBt setTitle:@"MyTitle" forState:UIControlStateNormal];
[barBt addTarget:self action: @selector(pressed:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barItem =  [[UIBarButtonItem alloc]init];
[barItem setCustomView:barBt];
self.navigationItem.leftBarButtonItem = barItem;

Upvotes: 5

Shubhank
Shubhank

Reputation: 21805

You can only have image or text inside the UIBarbuttonItem, the < is added by iOS by default as a back button for the navigation hierarchy.

You have to design the < button in the image itself if you want both image and the < in the barButton.

Upvotes: 3

Related Questions