码迷,mamicode.com
首页 > 其他好文 > 详细

封装 加载loading动画

时间:2016-05-13 08:20:16      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:

#import <UIKit/UIKit.h>

 @interface SSLoading : UIView

 - (instancetype)initWithFrame:(CGRect)frame;

- (void)showLoading:(UIColor *)backgroundColor alpha:(CGFloat)alpha;

-(void)disMiss;

 @end

 

 

#import "SSLoading.h"

#import "UIImage+GIF.h"

 

 

@implementation SSLoading

{

    UIView *SSLoadingBackView;

    UIImageView *SSLoadingImageView;

}

- (instancetype)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        self.hidden = YES;

        self.frame = frame;

    }

    return self;

 

}

 

- (void)showLoading:(UIColor *)backgroundColor alpha:(CGFloat)alpha

{

    

    self.hidden = NO;

    

    SSLoadingBackView = [[UIView alloc] initWithFrame:self.frame];

    SSLoadingBackView.backgroundColor = backgroundColor;

    SSLoadingBackView.alpha = alpha;

    [self addSubview:SSLoadingBackView];

    

    NSString  *name = @"loading@2x.gif";

    NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];

    NSData  *imageData = [NSData dataWithContentsOfFile:filePath];

    if (!SSLoadingImageView) {

        SSLoadingImageView = [[UIImageView alloc]init];

    }

    

    SSLoadingImageView.backgroundColor = [UIColor clearColor];

    SSLoadingImageView.image = [UIImage sd_animatedGIFWithData:imageData];

    SSLoadingImageView.frame = CGRectMake(self.frame.size.width/2-50, self.frame.size.height/2-50, 100, 100);

    SSLoadingImageView.contentMode = UIViewContentModeScaleAspectFit;

    [self addSubview:SSLoadingImageView];

}

 

-(void)disMiss

{

    

    for (UIView *view in self.subviews) {

        [view removeFromSuperview];

    }

    self.hidden = YES;

}

封装 加载loading动画

标签:

原文地址:http://www.cnblogs.com/xiaolingling1126/p/5485062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!