簡單封裝運用MBProgressHUD和SDWebImage寫一個頁面的gif加載動畫

//數(shù)據(jù)的加載時候動畫

+(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;

}

//根據(jù)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 ];

}

一個簡單的加載動畫,歡迎提出見解和相互學習

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容