您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

僅需幾行程式碼實現方便易用的狀態欄指示器

編輯:iOS 開發綜合

我們在使用微博等應用時,經常會看到狀態指示器。想知道它是怎麼做的嗎?本文就透過幾行程式碼,實現一個方便易用的狀態欄指示器。

微博項目的微博數提醒框

/** 提醒最新微博數量 */
- (void)showNewStatusCount:(NSInteger)count {
    if (count) {
        [[XZMStatusBarHUD sharedXZMStatusBarHUD] showNormal:[NSString stringWithFormat:@"有%ld條新的微博", count] position:64 animaDelay:0 configuration:^{
            [XZMStatusBarHUD sharedXZMStatusBarHUD].formView = self.view;
        }];
    } else {
        [[XZMStatusBarHUD sharedXZMStatusBarHUD] showNormal:@"沒有新的微博資料" position:64 animaDelay:0 configuration:^{
            [XZMStatusBarHUD sharedXZMStatusBarHUD].formView = self.view;
        }];
    }
}

載入成功並設定提醒框背景顏色

[[XZMStatusBarHUD sharedXZMStatusBarHUD] showSuccess:@"載入成功" position:0 animaDelay:0 configuration:^{
    [XZMStatusBarHUD sharedXZMStatusBarHUD].statusAlpha = 0.7;                 // 透明度
    [XZMStatusBarHUD sharedXZMStatusBarHUD].statusColor = [UIColor blueColor]; // 背景顏色
}];
// position:狀態欄提醒框位置,預設 0
// animaDelay:動畫持續時間,0 代表預設值 1.0

正在載入中並設定背景顏色

[[XZMStatusBarHUD sharedXZMStatusBarHUD] showLoading:@"正在載入中..." position:0 animaDelay:0 configuration:^{
    [XZMStatusBarHUD sharedXZMStatusBarHUD].statusColor = [UIColor redColor];
}];

透過 showNormal、showSuccess、showLoading 三個方法,並搭配 position、animaDelay、statusAlpha、statusColor 等屬性,就能輕鬆做出多樣化的狀態欄提示效果。以上就是狀態指示器的實作程式碼,希望對大家的學習有所幫助。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved