日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android自定义吐司通知,IOS 仿Android吐司提示框的实例(分享)

發布時間:2025/4/5 Android 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android自定义吐司通知,IOS 仿Android吐司提示框的实例(分享) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

直接上代碼

#import

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

總結

以上是生活随笔為你收集整理的android自定义吐司通知,IOS 仿Android吐司提示框的实例(分享)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。