Skip to content

Instantly share code, notes, and snippets.

@IskenHuang
Created February 23, 2014 05:15
Show Gist options
  • Save IskenHuang/9167259 to your computer and use it in GitHub Desktop.
Save IskenHuang/9167259 to your computer and use it in GitHub Desktop.
iOS Loading view. popup an loading view and covered all layout.
//
// LoadingView.h
//
//
// Created by Isken on 3/16/11.
// Copyright 2011 Isken. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LoadingView : UIView {
UIActivityIndicatorView *loadingAnimation;
UILabel *loadingLabel;
}
@property (nonatomic, retain) UIActivityIndicatorView *loadingAnimation;
@property (nonatomic, retain) UILabel *loadingLabel;
@end
//
// LoadingView.m
// gps_iphone
//
// Created by Isken on 3/16/11.
// Copyright 2011 Isken. All rights reserved.
//
#import "LoadingView.h"
@implementation LoadingView
@synthesize loadingAnimation, loadingLabel;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
//set animation
loadingAnimation = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[loadingAnimation setFrame:CGRectMake(self.frame.size.width/2-19, self.frame.size.height/2-19, 37, 37)];
[loadingAnimation startAnimating];
[self addSubview:loadingAnimation];
//set label
self.loadingLabel = [[UILabel alloc] init];
self.loadingLabel.text = @"Loading...";
[self.loadingLabel setTextColor:[UIColor whiteColor]];
[self.loadingLabel setBackgroundColor:[UIColor clearColor]];
[self.loadingLabel setFrame:CGRectMake(0, self.frame.size.height/2+25, self.frame.size.width, 30)];
[self.loadingLabel setTextAlignment:UITextAlignmentCenter];
[self addSubview:self.loadingLabel];
NSLog(@"view = %@", [self subviews]);
self.backgroundColor = [UIColor blackColor];
self.alpha = 0.8;
}
return self;
}
//-(id) init{
// [loadingAnimation startAnimating];
// self.backgroundColor = [UIColor blackColor];
// self.alpha = 0.8;
//}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code.
}
*/
- (void)dealloc {
[loadingLabel release];
[loadingAnimation release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment