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