toast使用

#import "toast.h"


@implementation toast


/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/


-(instancetype)initWithFrame:(CGRect)frame

{

    if(self = [super initWithFrame:frame]){

        self.backgroundColor=[UIColor blackColor];

        self.alpha=0.7;

        self.layer.cornerRadius=5.0;

        self.layer.masksToBounds=YES;

        self.textColor=[UIColor whiteColor];

        self.font=[UIFont boldSystemFontOfSize:16.0];

        self.textAlignment = NSTextAlignmentCenter;

        self.hidden = YES;

    }

    return self;

}


-(void)setLabelText:(NSString *)msg{

    self.text = msg;

    CGSize size=[self.text textSize:self.font withWidth:ScWidth-10];

    CGRect r=self.frame;

    r.size.width=size.width+20;

    r.origin.x=-r.size.width-200;

    self.frame = r;

    [self performSelector:@selector(fadeIn) withObject:nil afterDelay:0.5];

}


- (void)fadeIn{

    self.hidden = NO;

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:0.5f];

    CGRect r=self.frame;

    r.origin.x=(ScWidth-r.size.width)/2.0;

    self.frame = r;

    

    [UIView commitAnimations];

}


-(void)fadeOut

{

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1.0f];

    CGRect r=self.frame;

    r.origin.x=ScWidth+r.size.width+20;

    self.frame = r;

    [UIView commitAnimations];

}


-(void)setLabelText2:(NSString *)msg{

    self.text = msg;

    CGSize size=[self.text textSize:self.font withWidth:ScWidth-10];

    CGRect r=self.frame;

    r.size.width=size.width+20;

    r.origin.x=(ScWidth-size.width-20)/2;

    self.frame = r;

    self.alpha = 0.6;

    [self performSelector:@selector(fadeIn2) withObject:nil afterDelay:0.5];

}


- (void)fadeIn2{

    self.hidden = NO;

    [UIView beginAnimations:nil context:nil];

    self.alpha = 1;

    [UIView setAnimationDuration:0.5f];

    [UIView commitAnimations];

}


-(void)fadeOut2

{

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1.0f];

    self.hidden = YES;

    [UIView commitAnimations];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值