這篇文章主要介紹了iOS如何實(shí)現(xiàn)在狀態(tài)欄上顯示提醒信息的功能,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
先看效果圖
實(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í)際開(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)網(wǎng)站建設(shè)公司行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.rwnh.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
當(dāng)前名稱:iOS如何實(shí)現(xiàn)在狀態(tài)欄上顯示提醒信息的功能-創(chuàng)新互聯(lián)
分享路徑:http://www.rwnh.cn/article24/dddoje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、全網(wǎng)營(yíng)銷推廣、ChatGPT、網(wǎng)站排名、搜索引擎優(yōu)化、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容