IOS自定义请求uiwebview的loading框

.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





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lin&Yi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值