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

首頁 > 系統 > iOS > 正文

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

2020-07-26 02:34:38
字體:
來源:轉載
供稿:網友

直接上代碼

#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吐司提示框的實例(分享)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汝州市| 临武县| 南漳县| 彭阳县| 平泉县| 驻马店市| 临武县| 宜兰市| 寻甸| 绥化市| 新安县| 安塞县| 青河县| 朔州市| 南皮县| 苏尼特右旗| 漳浦县| 莱芜市| 静安区| 新平| 大丰市| 土默特右旗| 乌海市| 石门县| 科尔| 沙洋县| 惠州市| 中江县| 基隆市| 正蓝旗| 肇源县| 亳州市| 垦利县| 淳安县| 固阳县| 蕲春县| 遵义县| 琼中| 阿鲁科尔沁旗| 赤峰市| 大关县|