這篇文章主要介紹了iOS如何實(shí)現(xiàn)在狀態(tài)欄上顯示提醒信息的功能,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括堆龍德慶網(wǎng)站建設(shè)、堆龍德慶網(wǎng)站制作、堆龍德慶網(wǎng)頁(yè)制作以及堆龍德慶網(wǎng)絡(luò)營(yíng)銷策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,堆龍德慶網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到堆龍德慶省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
先看效果圖
實(shí)現(xiàn)這個(gè)效果,用到了JDStatusBarNotification,這是一個(gè)易于使用和定制的在狀態(tài)欄上顯示提醒信息的控件,可自定義顏色、字體以及動(dòng)畫(huà),支持進(jìn)度條展示,并可以顯示活動(dòng)指示器。
假設(shè)這么一個(gè)場(chǎng)景,需要調(diào)接口修改個(gè)人資料,這時(shí)有3個(gè)狀態(tài),正在修改、修改成功、修改失敗。我們可以寫(xiě)一個(gè)公共類,方便調(diào)用,譬如 NSObject+Common。
.h文件寫(xiě)方法
#import@interface NSObject (Common) - (void)showStatusBarQueryStr:(NSString *)tipStr; - (void)showStatusBarSuccessStr:(NSString *)tipStr; //此方法在實(shí)際開(kāi)發(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:@"修改失敗"];
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“iOS如何實(shí)現(xiàn)在狀態(tài)欄上顯示提醒信息的功能”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!