Initial commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// UITabBar+addRedPointBadge.m
|
||||
// Ifish
|
||||
//
|
||||
// Created by imac on 17/3/17.
|
||||
// Copyright © 2017年 lianlian. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UITabBar+addRedPointBadge.h"
|
||||
#define IFISHITEMNUNBERS 4.0
|
||||
@implementation UITabBar (addRedPointBadge)
|
||||
- (void)showBadgeOnItemIndex:(int)index{
|
||||
|
||||
//移除之前的小红点
|
||||
[self removeBadgeOnItemIndex:index];
|
||||
|
||||
UIView *badgeView = [[UIView alloc]init];
|
||||
badgeView.tag = 888 + index;
|
||||
badgeView.backgroundColor = RGB(252, 89, 89);
|
||||
CGRect tabFrame = self.frame;
|
||||
|
||||
//确定小红点的位置
|
||||
float percentX = (index +0.55) / IFISHITEMNUNBERS;
|
||||
CGFloat x = ceilf(percentX * tabFrame.size.width);
|
||||
CGFloat y = ceilf(0.1 * tabFrame.size.height);
|
||||
badgeView.frame = CGRectMake(x, y, 8, 8);
|
||||
badgeView.layer.cornerRadius = badgeView.frame.size.width/2;
|
||||
|
||||
[self addSubview:badgeView];
|
||||
[self bringSubviewToFront:badgeView];
|
||||
|
||||
}
|
||||
|
||||
- (void)hideBadgeOnItemIndex:(int)index{
|
||||
|
||||
//移除小红点
|
||||
[self removeBadgeOnItemIndex:index];
|
||||
|
||||
}
|
||||
|
||||
- (void)removeBadgeOnItemIndex:(int)index{
|
||||
|
||||
//按照tag值进行移除
|
||||
for (UIView *subView in self.subviews) {
|
||||
if (subView.tag == 888+index) {
|
||||
[subView removeFromSuperview];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user