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

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

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

先看效果圖


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

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

.h文件寫方法

#import <Foundation/Foundation.h>

@interface NSObject (Common)

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

@end

.m文件實(shí)現(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:@"正在修改個(gè)人信息"];
[self showStatusBarSuccessStr:@"個(gè)人信息修改成功"];
//[self showStatusBarError:error];
[self showStatusBarErrorStr:@"修改失敗"];

總結(jié)

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

相關(guān)文章

最新評(píng)論

丹巴县| 九龙城区| 禹州市| 弥勒县| 英德市| 胶南市| 通化县| 益阳市| 伊吾县| 宁乡县| 天祝| 黄梅县| 清流县| 长顺县| 凤城市| 自贡市| 弥勒县| 弥渡县| 蒲城县| 巴彦县| 开封市| 尚志市| 疏勒县| 桂林市| 东山县| 阿瓦提县| 洛川县| 平南县| 南皮县| 怀化市| 乌兰察布市| 突泉县| 无为县| 永吉县| 麻城市| 灵武市| 遂宁市| 渭南市| 昌平区| 壶关县| 射洪县|