這篇文章主要為大家展示了“IOS如何仿Android實現(xiàn)吐司提示框”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“IOS如何仿Android實現(xiàn)吐司提示框”這篇文章吧。
目前成都創(chuàng)新互聯(lián)已為上千多家的企業(yè)提供了網(wǎng)站建設、域名、網(wǎng)頁空間、網(wǎng)站托管維護、企業(yè)網(wǎng)站設計、河東網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
代碼如下
#import <UIKit/UIKit.h> @interface ShowToastView : UIView +(void)showToastView:(UIView *)uiview WithMessage:(NSString *)message; +(void)showToastViewShort:(UIView *)uiview WithMessage:(NSString *)message; +(void)showToastViewWithCostUpload:(UIView *)uiview WithMessage:(NSString *)message; +(void)showSmallHeightToastView:(UIView *)uiview WithMessage:(NSString *)message; @end
#import "ShowToastView.h" @implementation ShowToastView //Toast提示框 +(void)showToastView:(UIView *)uiview WithMessage:(NSString *)message { UIView *showview = [[UIView alloc]init]; showview.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.3]; showview.frame = CGRectMake(1, 1, 1, 1); showview.layer.cornerRadius = 5.0f; showview.layer.masksToBounds = YES; [uiview addSubview:showview]; UILabel *label = [[UILabel alloc]init]; CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height); label.text = message; label.textColor = [UIColor whiteColor]; label.textAlignment = 1; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:font(15)]; [showview addSubview:label]; showview.frame = CGRectMake((uiview.frame.size.width - LabelSize.width - 20)/2, uiview.frame.size.height - LabelSize.height-100, LabelSize.width+20, LabelSize.height+10); [UIView animateWithDuration:5.0 animations:^{ showview.alpha = 0; } completion:^(BOOL finished) { [showview removeFromSuperview]; }]; } +(void)showToastViewShort:(UIView *)uiview WithMessage:(NSString *)message { UIView *showview = [[UIView alloc]init]; showview.backgroundColor = [UIColor whiteColor]; showview.frame = CGRectMake(1, 1, 1, 1); showview.layer.cornerRadius = 5.0f; showview.layer.masksToBounds = YES; [uiview addSubview:showview]; UILabel *label = [[UILabel alloc]init]; CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height); label.text = message; label.textColor = [UIColor blackColor]; label.textAlignment = 1; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:15]; [showview addSubview:label]; showview.frame = CGRectMake((uiview.frame.size.width - LabelSize.width - 20)/2, uiview.frame.size.height - LabelSize.height-60, LabelSize.width+20, LabelSize.height+10); [UIView animateWithDuration:1 animations:^{ showview.alpha = 0; } completion:^(BOOL finished) { [showview removeFromSuperview]; }]; } //費用提報的Toast位置往上放一點 +(void)showToastViewWithCostUpload:(UIView *)uiview WithMessage:(NSString *)message { UIView *showview = [[UIView alloc]init]; showview.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.3]; showview.frame = CGRectMake(1, 1, 1, 1); showview.layer.cornerRadius = 5.0f; showview.layer.masksToBounds = YES; [uiview addSubview:showview]; UILabel *label = [[UILabel alloc]init]; CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; label.frame = CGRectMake(10, 5, LabelSize.width, LabelSize.height); label.text = message; label.textColor = [UIColor whiteColor]; label.textAlignment = 1; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:font(15)]; [showview addSubview:label]; showview.frame = CGRectMake((uiview.frame.size.width - LabelSize.width - 20)/2, uiview.frame.size.height - LabelSize.height-100, LabelSize.width+20, LabelSize.height+10); [UIView animateWithDuration:3.0 animations:^{ showview.alpha = 0; } completion:^(BOOL finished) { [showview removeFromSuperview]; }]; } //點擊開始按鈕的時候提示沒有任務,但是由于字數(shù)太多,高度又和寬度有一定的對比,所以在這里改成小一點高度 +(void)showSmallHeightToastView:(UIView *)uiview WithMessage:(NSString *)message { UIView *showview = [[UIView alloc]init]; showview.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.3]; showview.frame = CGRectMake(1, 1, 1, 1); showview.layer.cornerRadius = 5.0f; showview.layer.masksToBounds = YES; [uiview addSubview:showview]; UILabel *label = [[UILabel alloc]init]; CGSize LabelSize = [message sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290, 9000)]; label.frame = CGRectMake(10, 0, LabelSize.width, LabelSize.height); label.text = message; label.textColor = [UIColor whiteColor]; label.textAlignment = 1; label.backgroundColor = [UIColor clearColor]; label.font = [UIFont boldSystemFontOfSize:font(15)]; [showview addSubview:label]; showview.frame = CGRectMake((uiview.frame.size.width - LabelSize.width - 20)/2, uiview.frame.size.height - LabelSize.height-60, LabelSize.width+20, LabelSize.height-5); [UIView animateWithDuration:5.0 animations:^{ showview.alpha = 0; } completion:^(BOOL finished) { [showview removeFromSuperview]; }]; } @end
使用方法
[ShowToastView showToastView:self.view WithMessage:@"用戶名或密碼錯誤"];
以上是“IOS如何仿Android實現(xiàn)吐司提示框”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
分享文章:IOS如何仿Android實現(xiàn)吐司提示框
當前地址:http://muchs.cn/article28/joodjp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供標簽優(yōu)化、動態(tài)網(wǎng)站、企業(yè)建站、服務器托管、靜態(tài)網(wǎng)站、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)