最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS TabBarItem設(shè)置紅點(diǎn)(未讀消息)

 更新時(shí)間:2017年04月10日 11:53:22   作者:rockyMJ  
本文主要介紹了iOS利用TabBarItem設(shè)置紅點(diǎn)(未讀消息)的相關(guān)知識(shí)。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧

實(shí)現(xiàn)原理:

其實(shí)是自定義一個(gè)view,將view添加到UITabBar上面,也可以是一個(gè)按鈕,設(shè)置背景圖片,和label。

廢話少說(shuō)直接上代碼

搞一個(gè)UITabBar的分類

#import <UIKit/UIKit.h>
@interface UITabBar (Extension)
- (void)showBadgeOnItmIndex:(int)index;
- (void)hideBadgeOnItemIndex:(int)index;
@end
#import "UITabBar+Extension.h"
#define TabbarItemNums 5.0
@implementation UITabBar (badge)
//顯示紅點(diǎn)
- (void)showBadgeOnItmIndex:(int)index{
 [self removeBadgeOnItemIndex:index];
 //新建小紅點(diǎn)
 UIView *bview = [[UIView alloc]init];
 bview.tag = 888+index;
 bview.layer.cornerRadius = 5;
 bview.clipsToBounds = YES;
 bview.backgroundColor = [UIColor redColor];
 CGRect tabFram = self.frame;

 float percentX = (index+0.6)/TabbarItemNums;
 CGFloat x = ceilf(percentX*tabFram.size.width);
 CGFloat y = ceilf(0.1*tabFram.size.height);
 bview.frame = CGRectMake(x, y, 10, 10);
 [self addSubview:bview];
 [self bringSubviewToFront:bview];
}
//隱藏紅點(diǎn)
-(void)hideBadgeOnItemIndex:(int)index{
 [self removeBadgeOnItemIndex:index];
}
//移除控件
- (void)removeBadgeOnItemIndex:(int)index{
 for (UIView*subView in self.subviews) {
  if (subView.tag == 888+index) {
   [subView removeFromSuperview];
  }
 }
}
@end

最后在子控制器調(diào)用就可以啦

[self.tabBarController.tabBar showBadgeOnItmIndex:4];

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論

磴口县| 卓尼县| 榆社县| 分宜县| 涟水县| 南平市| 电白县| 大冶市| 喀喇| 林西县| 台江县| 保德县| 邢台市| 孟连| 阿克陶县| 普兰店市| 左权县| 奎屯市| 星座| 兰溪市| 涿州市| 灵宝市| 孝昌县| 双鸭山市| 民丰县| 河池市| 和田市| 夏河县| 宝山区| 酒泉市| 仁寿县| 金湖县| 临猗县| 宁波市| 巴林右旗| 隆子县| 弋阳县| 香格里拉县| 垫江县| 兴化市| 高淳县|