-1

I'm trying to display a number and an image as a bar button Item, but I don't know how to implement that. I'm adding a shopping cart button in my UINavigationController, which displays a shopping cart icon as an image, and the number of products inside the cart.

How can I make a similar button?

For example this is what the Amazon App has got: enter image description here

Paolo Stefan
  • 10,112
  • 5
  • 45
  • 64
sali
  • 179
  • 1
  • 12
  • 1
    Make a UIbutton, set its backgroundimage or just image. Place a tiny label at the position where you want to show the number of products. Set value of products as you want & perform your action by clicking the button. Remember, Button should be below the label in hierarchy or it will interfere with touch events. – NSNoob Dec 15 '15 at 07:43
  • Alternatively you can set background image of button and set button title to number of products, if that works for you. For me personally it always mucks up the UI so I go with first approach – NSNoob Dec 15 '15 at 07:44
  • have a look at http://stackoverflow.com/questions/5684636/how-to-add-badges-on-uibarbutton-item (i prefer second answer in this link) – Ravi Dec 15 '15 at 07:53
  • @NSNoob Thanks, I added the CustomButtron as leftBarButtonItem .But I notice that It destroys the backbarbutton .Why is that? – sali Dec 15 '15 at 08:34

3 Answers3

0

Hope This Helps..this code only for right side image

viewController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage.png"]];
UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage2.jpg"]]];    
viewController.navigationItem.rightBarButtonItem = item;    
Maulik shah
  • 1,664
  • 1
  • 19
  • 45
0

You can refer Badge Barbutton.By using this, can customise badgeBGColor,badgeTextColor, badgeFont, badgePadding, badgeMinSize, shouldHideBadgeAtZero and shouldAnimateBadge. Perfect for cart kind of bar icons.

Suhail kalathil
  • 2,673
  • 1
  • 13
  • 12
0

Please refer following link https://github.com/TanguyAladenise/BBBadgeBarButtonItem/blob/master/Example/BBBadgeBarButtonItem/BBViewController.m It might help.

Nilesh
  • 438
  • 5
  • 15