iOS development UI---Custom Load Wait box (MBPROGRESSHUD)

Source: Internet
Author: User

this article reprinted to http://blog.csdn.net/xunyn/article/details/8064984

Original Address http://www.189works.com/article-89289-1.html

Mbprogresshud is: Http://github.com/matej/MBProgressHUD

Here to introduce the user open source Mbprogresshud class, to implement the waiting box,

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:selfwithObject:nil];

}

Request a picture Resource

-(void) imageresourcerequest

{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

Based on network data, get to image resource

NSData *data = Http://www.cnblogs.com/snake-hand/archive/2012/08/13/[[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:imagewaitUntilDone: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:selfselector: @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

iOS development UI---Custom Load Wait box (MBPROGRESSHUD)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.