0

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

ZeMoon
  • 20,054
  • 5
  • 57
  • 98
Ham Dong Kyun
  • 756
  • 4
  • 28
  • Possible duplicate of [How to have a UIBarButtonItem with both image and text](http://stackoverflow.com/questions/3903018/how-to-have-a-uibarbuttonitem-with-both-image-and-text) – Sruit A.Suk Mar 07 '16 at 20:29

2 Answers2

5

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;
shtefane
  • 454
  • 2
  • 5
  • I'm having trouble with this implementation with the title not being showed. Perhaps it is related with the insets on the button? – valeCocoa Sep 22 '17 at 11:38
3

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.

Shubhank
  • 21,721
  • 8
  • 65
  • 83
  • Can I ask you an additional question? Let me explain with the calendar app in iPhone. Normally when you create a navigation hierarchy, Your app should start from the "Year View" then navigate through "Month View" so that you can activate the Back Button. But the iPhone calendar app starts from the "Month View" and cans still go back to "Year View". How is this implemented? – Ham Dong Kyun Mar 14 '14 at 07:56
  • you can assign viewControllers directly to `self.navigationController` object so the yearView Controller is kept as a viewcontroller and month view at the end , and you only see the monthView – Shubhank Mar 14 '14 at 07:58
  • Thanks again for fast answer. Please explain more about self.navigatorController. In which controller should I write this code in? – Ham Dong Kyun Mar 14 '14 at 08:01