您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“IOS如何仿Android實(shí)現(xiàn)吐司提示框”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“IOS如何仿Android實(shí)現(xiàn)吐司提示框”這篇文章吧。
代碼如下
#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]; }]; } //費(fèi)用提報(bào)的Toast位置往上放一點(diǎn) +(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]; }]; } //點(diǎn)擊開始按鈕的時(shí)候提示沒有任務(wù),但是由于字?jǐn)?shù)太多,高度又和寬度有一定的對(duì)比,所以在這里改成小一點(diǎn)高度 +(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:@"用戶名或密碼錯(cuò)誤"];
以上是“IOS如何仿Android實(shí)現(xiàn)吐司提示框”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。