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

首頁 > 系統 > iOS > 正文

iOS在狀態欄上顯示提醒信息的功能定制

2019-10-21 18:46:06
字體:
來源:轉載
供稿:網友

先看效果圖

ios狀態欄,ios,顯示狀態欄,顯示提示信息

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

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

.h文件寫方法

#import <Foundation/Foundation.h>@interface NSObject (Common)- (void)showStatusBarQueryStr:(NSString *)tipStr;- (void)showStatusBarSuccessStr:(NSString *)tipStr;//此方法在實際開發中調用,調接口失敗返回的error- (void)showStatusBarError:(NSError *)error;//...- (void)showStatusBarErrorStr:(NSString *)tipStr;@end

.m文件實現方法

#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]; }}

調用方法

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

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網的支持。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金溪县| 德安县| 普宁市| 大港区| 德阳市| 英吉沙县| 永吉县| 遵化市| 石渠县| 屏山县| 应城市| 沙河市| 登封市| 革吉县| 临沂市| 柘荣县| 贞丰县| 大宁县| 团风县| 神农架林区| 东乡县| 吴堡县| 蒙自县| 宿迁市| 石林| 陆丰市| 寿光市| 九台市| 遵化市| 灯塔市| 博罗县| 梧州市| 边坝县| 荣成市| 柞水县| 盐边县| 灵山县| 定西市| 湘潭县| 方山县| 辉县市|