国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

IOS 仿Android吐司提示框的實例(分享)

2019-10-21 18:42:54
字體:
來源:轉載
供稿:網友

直接上代碼

#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];  }];}//點擊開始按鈕的時候提示沒有任務,但是由于字數太多,高度又和寬度有一定的對比,所以在這里改成小一點高度+(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吐司提示框的實例(分享)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安平县| 海盐县| 宝鸡市| 元朗区| 长宁区| 东源县| 蕉岭县| 德格县| 泸定县| 恩平市| 东海县| 榆树市| 左权县| 久治县| 峨山| 宣恩县| 广河县| 兰考县| 勃利县| 探索| 德清县| 祁连县| 江北区| 上栗县| 平乡县| 涟水县| 合阳县| 南江县| 内黄县| 鄂托克旗| 宁阳县| 鸡泽县| 凯里市| 华宁县| 诸城市| 永春县| 德安县| 徐水县| 天柱县| 林西县| 台中县|