国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

自定義Tabbar的badgeView

2019-11-07 23:26:22
字體:
來源:轉載
供稿:網友

UITabBar類別.h文件

#import <UIKit/UIKit.h>@interface UITabBar (Badge)- (void)showBadgeOnItemIndex:(int)index; //顯示小紅點- (void)hideBadgeOnItemIndex:(int)index; //隱藏小紅點@end

UITabBar類別.m文件

#import "UITabBar+Badge.h"#define TABBARCount 4 //tabbar個數@implementation UITabBar (Badge)//顯示小紅點- (void)showBadgeOnItemIndex:(int)index{ //移除之前的小紅點 [self removeBadgeOnItemIndex:index]; //新建小紅點 UIView *badgeView = [[UIView alloc]init]; badgeView.tag = 888 + index; badgeView.layer.cornerRadius = 5;//圓形 badgeView.backgroundColor = [UIColor redColor];//顏色:紅色 CGRect tabFrame = self.frame; //確定小紅點的位置 float percentX = (index +0.7)/TABBARCount ; CGFloat x = ceilf(percentX * tabFrame.size.width); CGFloat y = ceilf(0.1 * tabFrame.size.height); badgeView.frame = CGRectMake(x, y, 10, 10);//圓形大小為10 [self addSubview: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

該內容都是在網上找資料再根據自身需求修改的,若有侵權,請聯系我!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 济阳县| 宁夏| 磐石市| 巴林右旗| 达尔| 酉阳| 岑巩县| 建宁县| 凤凰县| 灵武市| 菏泽市| 五华县| 旬阳县| 平远县| 安吉县| 平陆县| 双柏县| 射洪县| 阳谷县| 葫芦岛市| 麦盖提县| 龙岩市| 象州县| 米泉市| 富裕县| 肥东县| 濉溪县| 洮南市| 赣州市| 武鸣县| 苍山县| 丁青县| 大渡口区| 东明县| 肃北| 报价| 长垣县| 鱼台县| 虎林市| 治多县| 广南县|