国产探花免费观看_亚洲丰满少妇自慰呻吟_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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 衡东县| 柞水县| 定陶县| 葫芦岛市| 华容县| 耿马| 阿克苏市| 平远县| 寿宁县| 普安县| 甘孜| 米脂县| 涿鹿县| 宝应县| 津市市| 延寿县| 珲春市| 平乐县| 梅河口市| 志丹县| 桓台县| 察哈| 平邑县| 罗源县| 龙门县| 沈阳市| 独山县| 手游| 五莲县| 汉寿县| 叙永县| 蒲城县| 峨眉山市| 澎湖县| 奇台县| 万宁市| 阿尔山市| 山丹县| 牙克石市| 兰溪市| 巩义市|