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

iOS在狀態(tài)欄上顯示提醒信息的功能定制

 更新時間:2017年06月09日 09:38:18   作者:踏歌尋方  
這篇文章主要給大家介紹了iOS在狀態(tài)欄上顯示提醒信息的相關(guān)資料,實現(xiàn)后的效果非常不錯,文中給出了詳細的示例代碼供大家參考學(xué)習(xí),需要的朋友們下面來一起看看吧。

先看效果圖


實現(xiàn)這個效果,用到了JDStatusBarNotification,這是一個易于使用和定制的在狀態(tài)欄上顯示提醒信息的控件,可自定義顏色、字體以及動畫,支持進度條展示,并可以顯示活動指示器。

假設(shè)這么一個場景,需要調(diào)接口修改個人資料,這時有3個狀態(tài),正在修改、修改成功、修改失敗。我們可以寫一個公共類,方便調(diào)用,譬如 NSObject+Common。

.h文件寫方法

#import <Foundation/Foundation.h>

@interface NSObject (Common)

- (void)showStatusBarQueryStr:(NSString *)tipStr;
- (void)showStatusBarSuccessStr:(NSString *)tipStr;
//此方法在實際開發(fā)中調(diào)用,調(diào)接口失敗返回的error
- (void)showStatusBarError:(NSError *)error;
//...
- (void)showStatusBarErrorStr:(NSString *)tipStr;

@end

.m文件實現(xiàn)方法

#import "NSObject+Common.h"
#import "JDStatusBarNotification.h"

@implementation NSObject (Common)

//error返回的tipStr
- (NSString *)tipFromError:(NSError *)error {
 if (error && error.userInfo) {
  NSMutableString *tipStr = [[NSMutableString alloc] init];
  if ([error.userInfo objectForKey:@"msg"]) {
   NSArray *msgArray = [[error.userInfo objectForKey:@"msg"] allValues];
   NSUInteger num = [msgArray count];
   for (int i = 0; i < num; i++) {
    NSString *msgStr = [msgArray objectAtIndex:i];
    if (i+1 < num) {
     [tipStr appendString:[NSString stringWithFormat:@"%@\n", msgStr]];
    }else{
     [tipStr appendString:msgStr];
    }
   }
  }else{
   if ([error.userInfo objectForKey:@"NSLocalizedDescription"]) {
    tipStr = [error.userInfo objectForKey:@"NSLocalizedDescription"];
   }else{
    [tipStr appendFormat:@"ErrorCode%ld", (long)error.code];
   }
  }
  return tipStr;
 }
 return nil;
}

- (void)showStatusBarQueryStr:(NSString *)tipStr {
 [JDStatusBarNotification showWithStatus:tipStr styleName:JDStatusBarStyleSuccess];
 [JDStatusBarNotification showActivityIndicator:YES indicatorStyle:UIActivityIndicatorViewStyleWhite];
}

- (void)showStatusBarSuccessStr:(NSString *)tipStr {
 if ([JDStatusBarNotification isVisible]) {
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
   [JDStatusBarNotification showActivityIndicator:NO indicatorStyle:UIActivityIndicatorViewStyleWhite];
   [JDStatusBarNotification showWithStatus:tipStr dismissAfter:1.5 styleName:JDStatusBarStyleSuccess];
  });
 }else{
  [JDStatusBarNotification showActivityIndicator:NO indicatorStyle:UIActivityIndicatorViewStyleWhite];
  [JDStatusBarNotification showWithStatus:tipStr dismissAfter:1.0 styleName:JDStatusBarStyleSuccess];
 }
}

- (void)showStatusBarError:(NSError *)error {
 if ([JDStatusBarNotification isVisible]) {
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
   [JDStatusBarNotification showActivityIndicator:NO indicatorStyle:UIActivityIndicatorViewStyleWhite];
   [JDStatusBarNotification showWithStatus:[self tipFromError:error] dismissAfter:1.5 styleName:JDStatusBarStyleError];
  });
 }else{
  [JDStatusBarNotification showActivityIndicator:NO indicatorStyle:UIActivityIndicatorViewStyleWhite];
  [JDStatusBarNotification showWithStatus:[self tipFromError:error] dismissAfter:1.5 styleName:JDStatusBarStyleError];
 }
}

- (void)showStatusBarErrorStr:(NSString *)tipStr {
 if ([JDStatusBarNotification isVisible]) {
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
   [JDStatusBarNotification showActivityIndicator:NO indicatorStyle:UIActivityIndicatorViewStyleWhite];
   [JDStatusBarNotification showWithStatus:tipStr dismissAfter:1.5 styleName:JDStatusBarStyleError];
  });
 }else{
  [JDStatusBarNotification showActivityIndicator:NO indicatorStyle:UIActivityIndicatorViewStyleWhite];
  [JDStatusBarNotification showWithStatus:tipStr dismissAfter:1.5 styleName:JDStatusBarStyleError];
 }
}

調(diào)用方法

[self showStatusBarQueryStr:@"正在修改個人信息"];
[self showStatusBarSuccessStr:@"個人信息修改成功"];
//[self showStatusBarError:error];
[self showStatusBarErrorStr:@"修改失敗"];

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

  • iOS開發(fā)學(xué)習(xí)TableView展現(xiàn)一個list實例

    iOS開發(fā)學(xué)習(xí)TableView展現(xiàn)一個list實例

    這篇文章主要為大家介紹了iOS系列學(xué)習(xí)TableView展現(xiàn)一個list實例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • 詳解iOS中position:fixed吸底時的滑動出現(xiàn)抖動的解決方案

    詳解iOS中position:fixed吸底時的滑動出現(xiàn)抖動的解決方案

    這篇文章主要介紹了詳解iOS中position:fixed吸底時的滑動出現(xiàn)抖動的解決方案,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • IOS實現(xiàn)自定義透明背景的tabbar

    IOS實現(xiàn)自定義透明背景的tabbar

    這篇文章介紹的是在IOS中怎樣把tabbar背景設(shè)置為透明,有需要的小伙伴們可以參考借鑒。
    2016-08-08
  • iOS開發(fā)之1行代碼實現(xiàn)緩存計算及清除緩存

    iOS開發(fā)之1行代碼實現(xiàn)緩存計算及清除緩存

    這篇文章主要給大家介紹了關(guān)于iOS開發(fā)之1行代碼實現(xiàn)緩存計算及清除緩存的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位iOS開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • iOS路由(MGJRouter)的實現(xiàn)

    iOS路由(MGJRouter)的實現(xiàn)

    這篇文章主要介紹了iOS路由(MGJRouter)的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-09-09
  • iOS圖片壓縮、濾鏡、剪切及渲染等詳解

    iOS圖片壓縮、濾鏡、剪切及渲染等詳解

    這篇文章主要給大家介紹了關(guān)于iOS圖片壓縮、濾鏡、剪切及渲染等的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • iOS中UIActivityIndicatorView的用法及齒輪等待動畫實例

    iOS中UIActivityIndicatorView的用法及齒輪等待動畫實例

    UIActivityIndicatorView活動指示器最常見的用法便是用來制作那個程序中的齒輪轉(zhuǎn)動的等待效果,接下來我們回來簡單整理iOS中UIActivityIndicatorView的用法及齒輪等待動畫實例:
    2016-05-05
  • IOS 九宮格布局實現(xiàn)方法

    IOS 九宮格布局實現(xiàn)方法

    這篇文章主要介紹了IOS 九宮格布局實現(xiàn)方法,及實例代碼,需要的朋友可以參考下
    2016-09-09
  • iOS中設(shè)置清除緩存功能的實現(xiàn)方法

    iOS中設(shè)置清除緩存功能的實現(xiàn)方法

    清除緩存基本上都是在設(shè)置界面的某一個Cell,于是我們可以把清除緩存封裝在某一個自定義Cell中,現(xiàn)在位大家介紹一種最基礎(chǔ)的清除緩存的方法,感興趣的朋友一起看看吧
    2017-07-07
  • iOS獲取驗證碼倒計時效果

    iOS獲取驗證碼倒計時效果

    這篇文章主要為大家詳細介紹了iOS獲取驗證碼倒計時效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11

最新評論

阿鲁科尔沁旗| 周口市| 安图县| 博罗县| 皋兰县| 宜良县| 保亭| 乳山市| 峡江县| 集安市| 上犹县| 罗田县| 西乡县| 潼南县| 温州市| 昌江| 青铜峡市| 社旗县| 湄潭县| 普定县| 瑞昌市| 莱州市| 花莲县| 汾西县| 黑龙江省| 武山县| 北碚区| 黄大仙区| 吴桥县| 新郑市| 扶余县| 前郭尔| 栾城县| 宜阳县| 高淳县| 景东| 贺州市| 留坝县| 大丰市| 惠州市| 泗洪县|