0

This is a bit of a hack, but trying to get a badge on a toolbaritem. Almost there, but it appears in the back, tried normal methods to get to front with no luck.

Behind a toolbar

deletedCountBadge = [CustomBadge customBadgeWithString:@"0"];
deletedCountBadge.frame = CGRectMake(100,10,25,25);

UIView *view = (UIView *)[bottomToolBar.subviews objectAtIndex:0];
[view addSubview:deletedCountBadge];
ort11
  • 3,359
  • 4
  • 36
  • 69
  • 1
    did you try [view bringSubviewToFront:deletedCountBadge];? – Simone Pistecchia Mar 25 '13 at 15:54
  • My inclination is to add the badge to the toolbar and then call `[toolbar:bringSubviewToFront:badge]`. Not sure if you've tried that already though. – Carl Veazey Mar 25 '13 at 15:55
  • [bottomToolBar.subviews objectAtIndex:0] looks like toolbar background view, how about adding deleteCountBadge to bottomToolBar direct: [bottomToolBar addSubview: deletedCountBadge] – pcholberg Mar 25 '13 at 15:58
  • The bring to font does not work. I wanted the badge to be "on top of" the left most button. Have tried where view is from objectAtIndex:1 with same result. If I addSubview, then the badge has it's own space and is not on top of the button. Will probably have to make a custom button and put the badge in it and then add to toolbar – ort11 Mar 25 '13 at 17:37

1 Answers1

0

Got it to work with a couple of different pointers on the net.

1) If you are moving the toolbar around at all (.frame=) make sure to set the items after the layout

2) Can use negative spacing items to get it to show up where you want.

enter image description here

UIBarButtonItem *deleteBadge = [BarButtonItemBadge barButtonItemBadge:@"1" insideColor:[UIColor blueColor]];

UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSeperator.width = -30;

[bottomToolBarDictionaryButtonItems addObject:deleteBadge];
[bottomToolBarDictionaryButtonItems addObject:negativeSeperator];

// after any layout, of tool bar

[bottomToolBar setItems:bottomToolBarDictionaryButtonItems];
ort11
  • 3,359
  • 4
  • 36
  • 69