How to use a custom UIImage as an UITabBarItem Badge?

无人久伴 提交于 2019-12-23 19:54:17

问题


How can I add a custom UIImage as the Badge for a UITabBarItem?
I.e It will show up when the badge value of the UITabbarItem is set.


回答1:


Consider subclassing UITabBarItem and drawing it yourself




回答2:


Sascha Paulus wrote a great class that does just this:

CustomBadge2.0

You can of course use it in combination with subclassing UITabBarItem.




回答3:


u can use the following custom class for CustomBadge:

https://github.com/ckteebe/CustomBadge/tree/master/Classes

i hope this will help you.




回答4:


Can have a look inside here. Here custom item is added as a UILabel. Consider using your own choices here.

Demo

and only two line of code, to get you go

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  //supplying the animation parameter
  [UITabBarItem setDefaultAnimationProvider:[[DefaultTabbarBadgeAnimation alloc] init]];
  [UITabBarItem setDefaultConfigurationProvider:[[DefaultSystemLikeBadgeConfiguration alloc] init]];

  //rest of your code goes following...

  return YES;
}


来源:https://stackoverflow.com/questions/8288656/how-to-use-a-custom-uiimage-as-an-uitabbaritem-badge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!