Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set BadgeValue for ToolbarItems.UIBarButtonItem in MonoTouch

I'm pretty new to MonoTouch development, but I've been using the handy ToolbarItems property on the UIViewController to show some toolbar buttons and now I'm looking for a way to set the BadgeValue on some of those buttons.

It seems that the UIBarButtonItem class is missing the BadgeValue property you see on UITabBarItem, so the question is - how to set the badge value for a UIBarButtonItem in the ToolbarItems collection ?

UIBarButtonItem item1 = new UIBarButtonItem() { Title = "test" };
//item1.BadgeValue = "3"; //this doesn't work
ToolbarItems = new UIBarButtonItem[] { item1 };
like image 433
Johan Danforth Avatar asked Nov 14 '22 00:11

Johan Danforth


1 Answers

Both UIBarButtonItem and UITabBarItem inherit from UIBarItem. Sadly BadgeValue is only available for UITabBarItem so you'll need to reimplement this feature yourself.

This question (and answer) should help you: How to add Badges on UIBarbutton item?

But be warned that it might now look as good as a real badge.

like image 194
poupou Avatar answered Dec 07 '22 01:12

poupou