IOS UIActivityIndicatorView 等待指示器

自己做的一个 等待指示器  

 

#import <UIKit/UIKit.h>

 

@interface RockIndicatorView : UIView

{

    

}

 

@property(nonatomic,strong) UIView * indBgView;

@property(nonatomic,strong) UIActivityIndicatorView * indView;

@property(nonatomic,strong) UILabel * textLabel;

 

 

+(void)showWihtParent:(UIView * )parentView;

 

+(void)dismiss;

 

 

@end

 

 

//////////////////////////////////////////////////////////////////////////////////////////////////////

 

//

//  RockIndicatorView.m

//  test_demo

//

//  Created by zhuang chaoxiao on 14-5-18.

//  Copyright (c) 2014 zhuang chaoxiao. All rights reserved.

//

 

#import "RockIndicatorView.h"

 

@implementation RockIndicatorView

 

 

 

 

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // Initialization code

        

        self.backgroundColor = [UIColorclearColor];

        self.frame = [[UIScreen mainScreen] bounds];

        self.userInteractionEnabled = NO;

        

    }

    returnself;

}

 

 

+(RockIndicatorView*)shareView

{

    static RockIndicatorView * indView = nil;

    staticdispatch_once_t  once;

    

    dispatch_once(&once , ^(void){

        

        indView = [[RockIndicatorViewalloc]initWithFrame:[[UIScreenmainScreen] bounds]];

        

    });

    

    

    return indView;

    

}

 

 

-(UILabel*)textLabel

{

    if( _textLabel == nil )

    {

        CGRect rect = CGRectMake(0, 0, 50, 12);

        _textLabel = [[UILabel alloc]initWithFrame:rect];

        _textLabel.text = @"加载中...";

        _textLabel.font = [UIFont systemFontOfSize:10];

        _textLabel.textColor = [UIColor whiteColor];

        

        

        [self.indBgViewaddSubview:_textLabel];

        

        

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStylealloc]init];

        paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;

        NSDictionary *attributes = @{NSFontAttributeName:[UIFontsystemFontOfSize:10], NSParagraphStyleAttributeName:paragraphStyle.copy};

        

        CGSize labelSize = [_textLabel.textboundingRectWithSize:CGSizeMake(50,12) options:NSStringDrawingUsesLineFragmentOriginattributes:attributes context:nil].size;

        

        labelSize.height = ceil(labelSize.height);

        labelSize.width = ceil(labelSize.width);

        

        _textLabel.frame = CGRectMake(0, 0, labelSize.width, labelSize.height);

        _textLabel.center = CGPointMake(self.indBgView.frame.size.width/2, self.indBgView.frame.size.height/2+10);

    }

    

    return  _textLabel;

}

 

-(UIView *)indBgView

{

    if( _indBgView == nil )

    {

        CGRect rect = CGRectMake(0, 0, 60, 60);

        

        _indBgView = [[UIView alloc]initWithFrame:rect];

        

        rect = [[UIScreen mainScreen] bounds];

        

        _indBgView.backgroundColor = [UIColorblackColor];

        _indBgView.center = CGPointMake(rect.origin.x + rect.size.width/2, rect.origin.y + rect.size.height/2);

        _indBgView.userInteractionEnabled = NO;

        _indBgView.alpha = 0;

        _indBgView.layer.cornerRadius = 10.0f;

        

        [self addSubview:_indBgView];

    }

    

    return_indBgView;

}

 

 

-(UIActivityIndicatorView*)indView

{

    if( _indView == nil )

    {

        CGRect rect = CGRectMake(0, 0, 60, 60);

        _indView = [[UIActivityIndicatorViewalloc]initWithFrame:rect];

        _indView.center = CGPointMake(self.indBgView.frame.size.width/2, self.indBgView.frame.size.height/2 - 10);

        

        [self.indBgViewaddSubview:_indView];

        

    }

    

    return_indView;

}

 

 

-(void)showAnimWithParent:(UIView*)parentView

{

    [parentView addSubview:self];

    

    [self.indViewstartAnimating];

    

    if( self.textLabel ){}

    

    dispatch_async(dispatch_get_main_queue(), ^(void)

                   {

                       [self.indView startAnimating];

                      

                       [UIView animateWithDuration:1.0f animations:^(void)

                        {

                            self.indBgView.alpha = 1.0f;

                            

                        }];

                   });

    

}

 

 

-(void)dismissFromParent

{

    dispatch_async(dispatch_get_main_queue(), ^(void)

                   {

                       [UIView animateWithDuration:1.0f animations:^(void)

                        {

                            self.indBgView.alpha = 0.0f;

                            

                        } completion:^(BOOL finished)

                        {

                            if( finished )

                            {

                                [self removeFromSuperview];

                            }

                        }];

                       

                   });

}

 

 

+(void)showWihtParent:(UIView * )parentView

{

    [[RockIndicatorViewshareView] showAnimWithParent:parentView];

}

 

 

 

 

+(void)dismiss

{

    [[RockIndicatorViewshareView] dismissFromParent];

}

 

 

 

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect

{

    // Drawing code

}

*/

 

@end

posted on 2014-05-18 23:17  景树园  阅读(290)  评论(0编辑  收藏  举报

导航