自己做的一个 等待指示器

#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

IOS UIActivityIndicatorView 等待指示器的更多相关文章

  1. 使用开源库 MBProgressHUD 等待指示器

    source https://github.com/jdg/MBProgressHUD MBProgressHUD is an iOS drop-in class that displays a tr ...

  2. iOS UIActivityIndicatorView 的使用

    UIActivityIndicatorView 非常简单 ,就是一个转圈圈的控件:http://blog.csdn.net/zhaopenghhhhhh/article/details/1209265 ...

  3. UIActivityIndicatorView活动指示器

    活动指示器(UIActivityIndicatorView)可以告知用户有一个操作正在进行中.派生自UIView,所以他是视图,也可以附着在视图上. 一.创建 UIActivityIndicatorV ...

  4. iOS UIActivityIndicatorView

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle ...

  5. IOS UIActivityIndicatorView动画

    ● 是一个旋转进度轮,可以用来告知用户有一个操作正在进行中,一般 用initWithActivityIndicatorStyle初始化 ● 方法解析: ● - (void)startAnimating ...

  6. 转 UIActivityIndicatorView、UIProgressView 活动与进度指示器-IOS开发

    活动指示器(UIActivityIndicatorView)可以告知用户有一个操作正在进行中.进度指示器(UIProgressView )也具有同样功能,而且还可以告知用户离操作结束还多远. 这两个指 ...

  7. IOS开发之XCode学习014:警告对话框和等待提示器

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.警告对话框和等待提示器的概念 2.警告对话框 ...

  8. IOS开发UI基础UIActivityIndicatorView的属性

    UIActivityIndicatorView 1.activityIndicatorViewStyle设置指示器的样式UIActivityIndicatorViewStyleWhiteLarge U ...

  9. iOS - UI - UIActivityIndicatorView

    1.UIActivityIndicatorView HUD 指示器 UIActivityIndicatorView * indicatorView = [[UIActivityIndicatorVie ...

随机推荐

  1. linux设置和查看环境变量的方法

    1.    显示环境变量HOME $ echo $HOME /home/redbooks 2.    设置一个新的环境变量hello $ export HELLO="Hello!" ...

  2. Codeforces D546:Soldier and Number Game

    题目链接 输入t对数 a, b 求(b,a]内的每个数拆成素因子的个数和 这里每个数都可以写成素数的乘积,可以写成几个素数的和就有几个素因子,这里求的是(b,a]内的素因子和 思路: 素数的素因子个数 ...

  3. Vimrc配置以及Vim的常用操作

    """"""""""""""""&quo ...

  4. C程序的内存分配

    一.预备知识-程序的内存分配 一个由C/C++编译的程序占用的内存分为以下几个部分 1.栈区(stack)- 由编译器自动分配释放,存放函数的参数值,局部变量的值等.其操作方式类似于数据结构中的栈. ...

  5. 2.Sprng-IoC-Java反射例子

    1.Car.java package com.jike.spring.chapter03.reflect; public class Car { private String brand; priva ...

  6. iOS 深入理解RunLoop

    RunLoop 是 iOS 和 OSX 开发中非常基础的一个概念,这篇文章将从 CFRunLoop 的源码入手,介绍 RunLoop 的概念以及底层实现原理.之后会介绍一下在 iOS 中,苹果是如何利 ...

  7. [前端]利用a标签获取url里所需的内容

    function parseURL(url) { var a = document.createElement('a'); a.href = url; return { source: url, pr ...

  8. 解决eclipse maven 项目重新下载包这个问题

    问题:eclipse项目使用maven下载依赖包,但是有时候断网什么来着就不会自动下载了,挺蛋疼了. 所以,需要我们重新更新项目下载呢. 首先是要在maven的conf文件下setting.xml配置 ...

  9. SQLiteParameter不能将TableName作为参数

    http://stackoverflow.com/questions/1274432/sqlite-parameters-not-allowing-tablename-as-parameter Gen ...

  10. poj3307

    可以证明,每个符合的数都由2,3,5,7相乘得到. 依据猜想:下一个出现的数是由前面某个数乘上这几个数之一得到的新的数. 假设之前的数均满足序列,则因为下一个数必有2,3,5,7相乘得到,而这个数之前 ...