iOS开发精华专题iOS 开发列车Ios@IONIC

iOS开发自定义SC_ProgressHUD动画加载页面

2016-05-03  本文已影响1070人  Courage_SC

SC_ProgressHUD.h

#import <UIKit/UIKit.h>

@interface SC_ProgressHUD : UIView
//背景View
@property(nonatomic, strong)UIView *SC_backView;
//动图的imageView
@property(nonatomic, strong)UIImageView *SC_imageView;
//文字描述的label
@property(nonatomic, strong)UILabel *SC_label;
//存放动画的数组
@property(nonatomic, strong)NSMutableArray *SC_imageArray;
@end

SC_ProgressHUD.m

#import "SC_ProgressHUD.h"
#import "FitHeader.h"
@implementation SC_ProgressHUD

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _SC_backView = [[UIView alloc]initWithFrame:CGRectMake((self.frame.size.width - 150 * FitWidth) / 2.0, (self.frame.size.height - 170 * FitHeight) / 2.0, 150 * FitWidth, 100 * FitHeight)];
        _SC_backView.layer.masksToBounds = YES;
        _SC_backView.layer.cornerRadius = 10;
        _SC_backView.alpha = 1;
        [self addSubview:_SC_backView];
        
        _SC_imageView = [[UIImageView alloc]initWithFrame:CGRectMake((_SC_backView.frame.size.width - 50 * FitWidth) / 2.0, 10 * FitHeight, 50 * FitWidth, 50 * FitHeight)];
        [_SC_backView addSubview:_SC_imageView];
        
        _SC_label = [[UILabel alloc]initWithFrame:CGRectMake(0, 60 * FitHeight, _SC_backView.frame.size.width, 30 * FitHeight)];
        _SC_label.textColor = [UIColor whiteColor];
        _SC_label.textAlignment = 1;
        [_SC_backView addSubview:_SC_label];
        
        _SC_imageArray = [NSMutableArray array];
    }
    return self;
}


-(void)layoutSubviews{
    [super layoutSubviews];
    for (NSInteger i = 1; i < 13; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%ldc", i]];
        [_SC_imageArray addObject:image];
    }
    _SC_imageView.animationImages = _SC_imageArray;
    _SC_imageView.animationDuration = 1.5;
    _SC_imageView.animationRepeatCount = 900000;
    [_SC_imageView startAnimating];
}


@end

ViewController.h(使用自定义封装的类)

#import "SC_ProgressHUD.h"
@interface ViewController ()
@property(nonatomic, strong)SC_ProgressHUD *progressHUD;
@end
@implementation ViewController
- (void)viewDidLoad {
   //初始化_progressHUD,并添加_progressHUD
     _progressHUD = [[SC_ProgressHUD alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
     _progressHUD.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.9 alpha:1];
     _progressHUD.SC_label.text = @"Waiting...";
     _progressHUD.SC_label.textColor  = [UIColor grayColor];
     [self.view addSubview:_progressHUD];

     //数据加载完成之后移除_progressHUD
    //[_progressHUD removeFromSuperview];
}
上一篇下一篇

猜你喜欢

热点阅读