简单封装运用MBProgressHUD和SDWebImage写一个页面的gif加载动画

//数据的加载时候动画

+(void)showLoadingView:(UIView *)view{

static dispatch_once_t pred;

static UIView * hudCustomView;

dispatch_once(&pred, ^{

hudCustomView = [UIView new];

hudCustomView.backgroundColor = [UIColor whiteColor];

UIImage  * image = [UIImage sd_animatedGIFNamed:@"loading"];

hudCustomView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

UIImageView  *gifview=[[UIImageView alloc]initWithFrame:CGRectMake((hudCustomView.width - image.size.width)/2,(hudCustomView.height - image.size.height)/2,image.size.width, image.size.height)];

gifview.image = image;

[hudCustomView addSubview:gifview];

UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, hudCustomView.height/2 + 50, hudCustomView.width, 20)];

label.textAlignment = NSTextAlignmentCenter;

label.font = TEXTFONT(12);

label.textColor = [WSToolClass getColor:@"999999"];

label.text = @"o(>﹏<)o~,拼命加载中...";

[hudCustomView addSubview:label];

});

MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:view animated:YES];

hud.color = [UIColor whiteColor];//默认颜色太深了

hud.mode = MBProgressHUDModeCustomView;

hud.customView = hudCustomView;

}

//根据hex值得到具体的颜色

+ ( UIColor *) getColor:( NSString *)hexColor

{

unsigned int red, green, blue;

NSRange range;

range. length = 2 ;

range. location = 0 ;

[[ NSScanner scannerWithString :[hexColor substringWithRange :range]] scanHexInt :&red];

range. location = 2 ;

[[ NSScanner scannerWithString :[hexColor substringWithRange :range]] scanHexInt :&green];

range. location = 4 ;

[[ NSScanner scannerWithString :[hexColor substringWithRange :range]] scanHexInt :&blue];

return [ UIColor colorWithRed :( float )(red/ 255.0f ) green :( float )(green/ 255.0f ) blue :( float )(blue/ 255.0f ) alpha : 1.0f ];

}

一个简单的加载动画,欢迎提出见解和相互学习

你可能感兴趣的:(简单封装运用MBProgressHUD和SDWebImage写一个页面的gif加载动画)