IOS 仿Android吐司提示框的實(shí)例(分享)
直接上代碼
#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ù)太多,高度又和寬度有一定的對比,所以在這里改成小一點(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í)例(分享)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)簡單的popupwindow提示框
- Android中仿IOS提示框的實(shí)現(xiàn)方法
- Android使用Toast顯示消息提示框
- Android 自定義一套 Dialog通用提示框 (代碼庫)
- Android仿IOS自定義AlertDialog提示框
- Android仿QQ、微信聊天界面長按提示框效果
- Android仿百度谷歌搜索自動(dòng)提示框AutoCompleteTextView簡單應(yīng)用示例
- Android超實(shí)用的Toast提示框優(yōu)化分享
- Android實(shí)現(xiàn)Toast提示框圖文并存的方法
- Android編程之自定義AlertDialog(退出提示框)用法實(shí)例
- Android模擬美團(tuán)客戶端進(jìn)度提示框
- android 彈出提示框的使用(圖文實(shí)例)
- android實(shí)現(xiàn)彈出提示框
相關(guān)文章
iOS開發(fā)技巧之WeakSelf宏的進(jìn)化詳解
在程序中我們經(jīng)常用到Block,但寫weak self 時(shí)會(huì)比較繁瑣,下面這篇文章主要給大家介紹了關(guān)于iOS開發(fā)技巧之WeakSelf宏的進(jìn)化的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們一起來看看吧2018-05-05基于UIControl控件實(shí)現(xiàn)ios點(diǎn)贊功能
在開發(fā)當(dāng)中,可能很多時(shí)候都需要做個(gè)點(diǎn)贊的需求,如果用按鈕實(shí)現(xiàn),按鈕作為一個(gè)系統(tǒng)復(fù)合控件,外部是一個(gè) View--》UIControl的容器,本文給大家分享一個(gè)基于UIControl控件實(shí)現(xiàn)ios點(diǎn)贊功能,需要的朋友可以參考下2015-09-09iOS仿支付寶芝麻信用分?jǐn)?shù)儀表盤動(dòng)畫效果
這篇文章主要為大家詳細(xì)介紹了iOS仿支付寶芝麻信用分?jǐn)?shù)儀表盤動(dòng)畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09iOS 委托與文本輸入(內(nèi)容根據(jù)iOS編程編寫)
這篇文章主要介紹了iOS 委托與文本輸入(內(nèi)容根據(jù)iOS編程編寫) 的相關(guān)資料,需要的朋友可以參考下2016-09-09iOS錄屏和截屏監(jiān)聽的實(shí)現(xiàn)代碼
本篇文章主要介紹了iOS錄屏和截屏監(jiān)聽的實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05簡單介紹iOS開發(fā)中關(guān)于category的應(yīng)用
這篇文章主要介紹了iOS開發(fā)中關(guān)于category的應(yīng)用,代碼仍然基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-09-09IOS使用NSUserDefault去實(shí)現(xiàn)界面?zhèn)髦岛蛿?shù)據(jù)存儲(chǔ)
這篇文章主要介紹了IOS使用NSUserDefault去實(shí)現(xiàn)界面?zhèn)髦岛蛿?shù)據(jù)存儲(chǔ)的相關(guān)資料,需要的朋友可以參考下2017-07-07