iOS loading等待图

 1 #import "HXCActivity.h"
 2 #define Activity_WIDTH 40.f
 3 #define Activity_HEIGHT 40.f
 4 
 5 static UIWebView *_gifView;
 6 static UIWindow *window;
 7 static UIView *showview;
 8 @interface HXCActivity ()
 9 
10 @end
11 
12 @implementation HXCActivity
13 
14 
15 - (id)initWithFrame:(CGRect)frame
16 {
17     self = [super initWithFrame:frame];
18     
19     if (self)
20     {
21         self.backgroundColor = [UIColor clearColor];
22     }
23     
24     return self;;
25 }
26 
27 +(void)startGif
28 {
29     UIWindow * window = [UIApplication sharedApplication].keyWindow;
30     
31     showview =  [[UIView alloc]init];
32     showview.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
33     showview.frame = CGRectMake(0, 0, KscreenWidth, KscreenHeigh);
34     
35     [window addSubview:showview];
36     [_gifView.superview removeFromSuperview];
37     UIImage *image = [UIImage imageNamed:@"startLoading.gif"];
38     _gifView = [[UIWebView alloc]initWithFrame:CGRectMake(KscreenWidth/2-image.size.width/2/2, KscreenHeigh/2-image.size.height/2/2, image.size.width/2, image.size.height/2)];
39     [showview addSubview:_gifView];
40     NSData *gif = [NSData dataWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"startLoading" ofType:@"gif"]];
41     [_gifView loadData:gif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];
42 
43     _gifView.scalesPageToFit = YES;
44     //禁止滚动
45     _gifView.scrollView.scrollEnabled = NO;
46     //设置透明效果
47     _gifView.backgroundColor = [UIColor clearColor];
48     _gifView.opaque = 0;
49 
50     
51     UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, _gifView.bottom, KscreenWidth, 20)];
52     label.text = @"加载中,请稍候片刻···";
53     label.textColor = [UIColor colorWithWhite:0.8 alpha:1];
54     label.font = [UIFont systemFontOfSize:9];
55     label.textAlignment = NSTextAlignmentCenter;
56     [showview addSubview:label];
57 }
58 
59 +(void)stopGif
60 {
61 
62     [_gifView removeFromSuperview];
63     [_gifView.superview removeFromSuperview];
64     _gifView = nil;
65     [window removeFromSuperview];
66     window = nil;
67     [showview removeFromSuperview];
68     showview = nil;
69     
70 }

 

posted @ 2017-02-22 13:51  福泽小院  阅读(1169)  评论(0编辑  收藏  举报