IOS中的Android吐司代碼


#import <UIKit/UIKit.h>
#import "CustomDialog.h"
@interface SystemDialog :UIView{
    
}
- (id)initWithText:(NSString *)text;
- (void) show;
@end


#import "SystemDialog.h"
#import "AppDelegate.h"
@implementation SystemDialog

- (id)initWithText:(NSString *)text
{
    self = [super init];
    if (self) {
       
        self.backgroundColor=[UIColor blackColor];
        self.alpha=0.0;
        self.layer.cornerRadius = 6;
        self.layer.masksToBounds = YES;
        self.layer.borderWidth = 0;
        self.layer.borderColor =[[UIColor clearColor]CGColor];
        
        CGSize size=[text sizeWithFont:[UIFont boldSystemFontOfSize:16.0] constrainedToSize:CGSizeMake(200, 100) lineBreakMode:UILineBreakModeWordWrap];
        UILabel * titleLable=[[UILabel alloc] initWithFrame:CGRectMake(8,8,size.width,size.height)];
        titleLable.lineBreakMode = UILineBreakModeCharacterWrap;
        titleLable.numberOfLines = 0;
        titleLable.textColor=[UIColor whiteColor];
        titleLable.textAlignment=UITextAlignmentLeft;
        titleLable.backgroundColor=[UIColor clearColor];
        titleLable.font=[UIFont boldSystemFontOfSize:16.0];
        titleLable.text=text;
        [self addSubview:titleLable];

//        self.frame=CGRectMake((320-kControlWidth(titleLable)-16)/2,460-216-60,kControlWidth(titleLable)+16, kControlRbY(titleLable)+8);
        self.frame = CGRectMake((ScreenWidth - titleLable.width -16)/2, (ScreenHeight-64-216)+5, (titleLable.width + 16), (titleLable.height + 16));
        [titleLable release];
        
        [((AppDelegate*)[UIApplication sharedApplication].delegate).window addSubview:self];
    }
    return self;
}


- (void) show {
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0f];
    self.alpha=0.8;
    [self performSelector:@selector(hidden:) withObject:nil afterDelay:2.0];
    [UIView commitAnimations];
    
    
}

- (void) hidden:(id)sender{
    if ([self superview]) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.0f];
        self.alpha=0.0;
        [UIView commitAnimations];
    }
    
}



- (void)dealloc
{
    [super dealloc];
}

@end
相關文章
相關標籤/搜索