.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface LoadingView : UIView
{
}
@property (assign, nonatomic) NSInteger pointCount;
@property (strong, nonatomic) LoadingView * loadingView;
@property (strong, nonatomic) UILabel * loadingLabel;
@property (strong, nonatomic) UILabel * bgLabel;
@property (strong, nonatomic) UIActivityIndicatorView * activityView;
@property (strong, nonatomic) NSTimer * timer;
- (void)showLoadingView:(UIView *)superView;
- (void)removeView;
@end
.m
#import "LoadingView.h"
#import <QuartzCore/QuartzCore.h>
@implementation LoadingView
- (void)showLoadingView:(UIView *)superView
{
CGSize size = [UIScreen mainScreen].bounds.size;
//背景页面
self.loadingView = [[LoadingView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.loadingView setBackgroundColor:[UIColor lightGrayColor]];
[self.loadingView setAlpha:0.4];
[superView addSubview:self.loadingView];
//小的背景图片
self.bgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, size.width / 2, 100)];
[self.bgLabel setBackgroundColor:[UIColor darkGrayColor]];
CGPoint point = CGPointMake(self.loadingView.center.x, self.loadingView.center.y + 10);
[self.bgLabel setCenter:point];
self.bgLabel.layer.cornerRadius = 10;
self.bgLabel.layer.masksToBounds = YES;
[superView addSubview:self.bgLabel];
//转圈页面
self.activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(size.width / 2 - 30, size.height / 2 - 30, 60.0f, 60.0f)];
[self.activityView setBackgroundColor:[UIColor clearColor]];
[self.activityView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
[superView addSubview:self.activityView];
[self.activityView startAnimating];
//提示文字
CGRect labelFrame = CGRectMake(size.width / 2, size.height / 2 + 30, size.width / 3, 50);
self.loadingLabel = [[UILabel alloc] initWithFrame:labelFrame];
point = CGPointMake(self.loadingView.center.x, self.loadingView.center.y + 35);
[self.loadingLabel setCenter:point];
self.loadingLabel.textAlignment = UITextAlignmentCenter;
self.loadingLabel.text = @"玩命加载中";
self.loadingLabel.textColor = [UIColor whiteColor];
self.loadingLabel.layer.cornerRadius = 30;
self.loadingLabel.backgroundColor = [UIColor clearColor];
[superView addSubview:self.loadingLabel];
self.pointCount = 0;
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updateLoadingLabel:) userInfo:nil repeats:YES];
}
- (void)updateLoadingLabel:(NSTimer *)timer
{
self.pointCount ++;
if (self.pointCount > 3)
{
self.pointCount = 0;
self.loadingLabel.text = @"玩命加载中";
}
else
{
NSString * msg = @"玩命加载中";
for (int i = 0; i < self.pointCount; i++)
{
msg = [NSString stringWithFormat:@"%@.",msg];
self.loadingLabel.text = msg;
}
}
}
- (void)removeView
{
[self.loadingView removeFromSuperview];
[self.loadingLabel removeFromSuperview];
[self.bgLabel removeFromSuperview];
[self.activityView stopAnimating];
[self.activityView removeFromSuperview];
[self.timer invalidate];
self.timer = nil;
}
@end
调用
self.MyLoadingView = [[LoadingView alloc]init];
[self.MyLoadingView showLoadingView:superView];
[self.MyLoadingView removeView];
下载链接
http://download.csdn.net/detail/linyang24/9193337