日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

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

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

直接上代碼

#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];

}];

}

//費(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í)候提示沒(méi)有任務(wù),但是由于字?jǐn)?shù)太多,高度又和寬度有一定的對(duì)比,所以在這里改成小一點(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í)例(分享)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

總結(jié)

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

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。