How to set a badge value on a UITabBarController item

这里写图片描述
Each view controller has access to a UITabBarItem. This is only displayed if the current view controller is part of a UITabBarController. A UITabBarItem has a badge value which is that little red mark above icon and name to the tab bar item itself (as shown in the screenshot above: LIVE is currently the badgeValue of the tab bar item).

Here’s how you can set the badge value:

// set the tab bar value (any NSString will work):
self.tabBarItem.badgeValue = @”LIVE”;

// make it disappear again
self.tabBarItem.badgeValue = nil;

// set it to a little red circle (no value, just an empty string)
self.tabBarItem.badgeValue = @”“;
This approach will work if you have direct access to the class in the view controller. More commonly though you’ll have your own class embedded in a UINavigationController, in which case its tab bar item (and title) is shown on that tab.

In which case you can access the tab bar item like this:

// set badge value on your own nav controller
self.navigationController.tabBarItem.badgeValue = @”LIVE”;
https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarItem_Class/Reference/Reference.html

copywrite :http://pinkstone.co.uk/how-to-set-a-badge-value-on-a-uitabbarcontroller-item/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值