First, the online download Mbprogesshud class files, directly into the project can be
Second, example analysis
In my project, the example is as follows:
1) The ShowImageViewController.h header file code is as follows:
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
@interface showimageviewcontroller:uiviewcontroller<mbprogresshuddelegate> {
NSString *_picurlstring;
Uiimageview *_imageview;
Mbprogresshud *_progresshud;
}
@property (nonatomic, copy) NSString *picurlstring;
@property (nonatomic, retain) Iboutlet Uiimageview *imageview;
@property (nonatomic, retain) Mbprogresshud *progresshud;
Request a picture Resource
-(void) imageresourcerequest;
Display picture information
-(void) DisplayImage: (UIImage *) image;
-(Ibaction) Dismissmodealview: (ID) sender;
-(void) Removemodalview;
@end
2) in the SHOWIMAGEVIEWCONTROLLER.M implementation file code is as follows:
#import "ShowImageViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation Showimageviewcontroller
@synthesize picurlstring = _picurlstring;
@synthesize ImageView = _imageview;
@synthesize Progresshud = _progresshud;
-(void) viewdidload
{
[Super Viewdidload];
Do any additional setup after loading the view from its nib.
Self.view.backgroundColor = [Uicolor Graycolor];
Self.view.alpha = 0.8;
Set the picture to rounded corners
Self.imageView.backgroundColor = [Uicolor Clearcolor];
Self.imageView.layer.borderColor = [Uicolor Lightgraycolor]. Cgcolor;
Self.imageView.layer.borderWidth = 5.0;
Self.imageView.layer.masksToBounds = YES;
Self.imageView.layer.cornerRadius = 10.0;
}
-(void) Viewwillappear: (BOOL) animated
{
[Super viewwillappear:animated];
Reset ImageView When you enter the view
[Self.imageview Setimage:nil];
[Self.imageview Setframe:cgrectmake (160, 200, 0, 0)];
Show Load Wait box
Self.progresshud = [[Mbprogresshud alloc] initWithView:self.view];
[Self.view AddSubview:self.progressHUD];
[Self.view BringSubviewToFront:self.progressHUD];
Self.progressHUD.delegate = self;
Self.progressHUD.labelText = @ "Loading ...";
[Self.progresshud Show:yes];
Open thread, request picture Resource
[Nsthread detachnewthreadselector: @selector (imageresourcerequest) totarget:self Withobject:nil];
}
Request a picture Resource
-(void) imageresourcerequest
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Based on network data, get to image resource
NSData *data = [[NSData alloc] Initwithcontentsofurl:[nsurl URLWithString:self.picUrlString]];
UIImage *image = [[UIImage alloc] initwithdata:data];
[Data release];
Back to main thread, display picture information
[Self Performselectoronmainthread: @selector (displayimage:) withobject:image Waituntildone:no];
[Image release];
[Pool release];
}
Display picture information
-(void) DisplayImage: (UIImage *) image
{
If the Self.progresshud is true, remove the Self.progresshud and set it to nil
if (Self.progresshud) {
[Self.progresshud Removefromsuperview];
[Self.progresshud release];
Self.progresshud = nil;
}
Picture slowly zoom in on the animation effect
[Self.imageview Setimage:image];
[UIView Beginanimations:nil Context:nil];
[UIView setanimationduration:0.5];
[Self.imageview Setframe:cgrectmake (40, 100, 240, 160)];
[UIView commitanimations];
}
-(void) viewdidunload
{
[Self setimageview:nil];
[Super Viewdidunload];
Release any retained subviews of the main view.
e.g. Self.myoutlet = nil;
}
-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation
{
Return YES for supported orientations
return (interfaceorientation = = uiinterfaceorientationportrait);
}
-(Ibaction) Dismissmodealview: (ID) Sender {
Set the timer, when the animation ends, the child view is removed from the parent view
[Nstimer scheduledtimerwithtimeinterval:0.5 target:self selector: @selector (removemodalview) Userinfo:nil Repeats:NO ];
[UIView Beginanimations:nil Context:nil];
[UIView setanimationduration:0.5];
[Self.imageview Setframe:cgrectmake (160, 200, 0, 0)];
[UIView commitanimations];
}
-(void) Removemodalview
{
[Self.view Removefromsuperview];
}
#pragma mark-
#pragma Mark Mbprogresshuddelegate Methods
-(void) Hudwashidden: (Mbprogresshud *) HUD {
NSLog (@ "HUD:%@", HUD);
Remove HUD from screens when the HUD is hidded
[Self.progresshud Removefromsuperview];
[Self.progresshud release];
Self.progresshud = nil;
}
-(void) dealloc
{
[_picurlstring release];
[_imageview release];
[Super Dealloc];
}
@end
Third, the effect shows
Iv. Summary
Using Mbprogresshud to implement Load wait box, visual effect greatly improved
Custom Load Wait box (MBPROGRESSHUD)