iOS 未讀訊息角標 仿QQ拖拽 簡單靈活 支援xib(源碼)

來源:互聯網
上載者:User

標籤:hub   sig   glin   適應   effect   integer   log   navig   pre   

一、效果

二、簡單用法

超級簡單,2行代碼整合;xib可0代碼整合,只需拖一個view關聯LFBadge類即可

支援pod匯入pod ‘LFKit/LFBadge‘

//一般view上加角標_badge1 = [[LFBadge alloc] init];[_badge1 addToTabBarItem:_view1];//BarButtonItem上加角標_badge2 = [[LFBadge alloc] init];[_badge2 addToBarButtonItem:self.navigationItem.rightBarButtonItem];//TabBarItem上加角標_badge3 = [[LFBadge alloc] init];[_badge3 addToTabBarItem:self.tabBarItem];

//賦值
//@"0"或者nil隱藏,@""顯示紅點,大於maxCount的數字字串顯示maxCount++,其他字串就顯示本來樣子(你也可以顯示new)
_badge1.count = @"1"
三、更多用法1.拖拽清除

加了清除回調就有拖拽功能,不加就沒有拖拽功能

 _badge1.clearBlock = ^{        NSLog(@"清除未讀訊息角標");    };
2.其他可定義的功能

具體見.h檔案,有詳細注釋

typedef NS_ENUM(NSInteger, LFBadgeType) {    LFBadgeType_Center,//Badge中心對準父視圖右上方    LFBadgeType_RightTop,//Badge右上方對準父視圖右上方    LFBadgeType_LeftBottom//Badge左下角對準父視圖右上方};/**未讀訊息角標控制項,支援xib和代碼2種方式使用,支援拖拽清除*/@interface LFBadge : UIView@property (nonatomic, strong) UIColor *badgeCorlor;//角標顏色,預設紅色@property (nonatomic, strong) UILabel *lbText;//預設白字,字型14,角標大小自動適應字型大小@property (nonatomic) BOOL needDisappearEffects;//是否需要消失特效,爆炸特效//最大數字,不設定則預設99,要在count之前設定@property (nonatomic, assign) NSInteger maxCount;//@"0"或者nil隱藏,@""顯示紅點,大於maxCount的數字字串顯示maxCount++,其他字串就顯示本來樣子(你也可以顯示new)@property (nonatomic, copy) NSString *count;@property (nonatomic, assign) CGFloat redDotSize;//紅點大小,不設定則預設8@property (nonatomic, assign) CGFloat maxDistance;//大圓脫離小圓的最大距離/**自行設定其他約束或者frame時下面2屬性無效****/@property (nonatomic) UIEdgeInsets edgeInsets;//對父視圖右上方的位移量,預設UIEdgeInsetsZero@property (nonatomic) LFBadgeType type;/**拖動清除回調(設定了這個才會有拖動效果)*/@property (nonatomic, copy) void(^clearBlock)(void);/**添加到父視圖右上方(自動加約束)*/- (void)addToView:(UIView*)superview;/**將角標加到TabBarItem右上方(自動加約束)*/- (void)addToTabBarItem:(UITabBarItem *)tabBarItem;/**將角標加到BarButtonItem右上方(自動加約束)*/- (void)addToBarButtonItem:(UIBarButtonItem *)barButtonItem;/**清除角標約束(如果不想加到父視圖右上方可調該方法,然後自行設定其他約束或者frame)*/- (void)clearBadgeConstraint;

LFBadge只是LFKit的一個子庫,源碼地址https://github.com/zhanglinfeng/LFKit

iOS 未讀訊息角標 仿QQ拖拽 簡單靈活 支援xib(源碼)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.