zoukankan      html  css  js  c++  java
  • 封装 加载loading动画

    #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;

    }

  • 相关阅读:
    算法:javascript截取字符串
    【转】解决memcached启动失败
    Ubuntu 16.04 安装 Apache, MySQL, PHP7
    phpstorm2016.3+xdebug调试
    (转)微信开发连接SAE数据库
    php图片上传服务器
    大数据整体市场规模达1000亿,金融、政务等行业应用占据七成份额
    “AI智客计划”
    人工智能 :眼纹识别技术大显神通,一眼认出你
    AI 芯片,是金山还是泡沫?
  • 原文地址:https://www.cnblogs.com/xiaolingling1126/p/5485062.html
Copyright © 2011-2022 走看看