码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发--tarBarItem右上方显示badgeValue

时间:2015-08-05 10:14:46      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

直接设置tabBarItem.badgeValue没有效果,找原因半天发现ViewController被NavigationViewController包着

需这样设置才行:

1 self.navigationController.tabBarItem.badgeValue = [[NSString alloc]initWithFormat:@"%d",count];

1. 如果有数字,直接使用 viewController.tabBarItem.badgeValue = @"1";

2. 没有数字,自己往tabbar加subView。

    需要注意的是坐标x,y一定要是整数,否则会有模糊

        UIImageView *dotImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"personinfo_unread@2x.png"]];

        dotImage.backgroundColor = [UIColor clearColor];

        dotImage.tag = RED_DOT_TAG;

        CGRect tabFrame = tabbarController.tabBar.frame;

        CGFloat x = ceilf(0.94 * tabFrame.size.width);

        CGFloat y = ceilf(0.2 * tabFrame.size.height);

        dotImage.frame = CGRectMake(x, y, 6, 6);

        [tabbarController.tabBar addSubview:dotImage];

        [dotImage release];

iOS开发--tarBarItem右上方显示badgeValue

标签:

原文地址:http://www.cnblogs.com/feiling/p/4703911.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!