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

首頁 > 系統(tǒng) > iOS > 正文

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

2020-07-26 02:47:48
字體:
供稿:網(wǎng)友

先看效果圖


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

假設(shè)這么一個(gè)場景,需要調(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)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對武林網(wǎng)的支持。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌兰浩特市| 阿拉善盟| 伊金霍洛旗| 岫岩| 云龙县| 呼和浩特市| 靖江市| 长垣县| 五莲县| 凌云县| 台中市| 汾阳市| 塔城市| 西城区| 客服| 西宁市| 巴塘县| 依兰县| 崇明县| 浦城县| 高尔夫| 杂多县| 瑞金市| 晋江市| 安泽县| 邢台县| 桦南县| 应用必备| 平顶山市| 自治县| 土默特右旗| 咸宁市| 玛纳斯县| 十堰市| 南溪县| 恩施市| 玛纳斯县| 临清市| 滦平县| 无为县| 通化县|