IOS development-use MBProgressHUD to increase user experience (2)

Source: Internet
Author: User

IOS development-use MBProgressHUD to increase user experience (2)

In the previous blog "iOS development-using MBProgressHUD to increase User Experience", I used MBProgressHUD encapsulated by others for loading prompts, which is quite convenient. Today, we use the native MBProgressHUD third-party library on Github for loading prompts, which is a little bit more complicated than someone else has encapsulated. The Code has been uploaded to: https://github.com/chenyufeng1991/usembprogresshud. The implementation steps are as follows:

(1) The network request number is also used for local implementation. (Please refer to the notes)

 

-(IBAction) sourceButtonPressed :( id) sender {// declare object; MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo: self. view animated: true]; // displayed text; hud. labelText = @ loading; AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager]; manager. responseSerializer = [AFHTTPResponseSerializer serializer]; // if you change it to POST, you can perform the POST request. // put the parameters to be passed directly into the URL, instead of in the dictionary. [manager GET: @ http://webservice.webxm L.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo? MobileCode = 18888888888 & userId = parameters: nil success: ^ (AFHTTPRequestOperation * operation, id responseObject) {NSString * string = [[NSString alloc] initWithData: responseObject encoding: encoding]; NSLog (@ success: % @, string); // load successfully. First, remove the original HUD; hud. removeFromSuperViewOnHide = true; [hud hide: true afterDelay: 0]; // a success prompt is displayed. MBProgressHUD * successHUD = [MBProgressHUD showHUDAddedTo: self. view animated: true]; successHUD. labelText = @ loaded successfully; successHUD. mode = MBProgressHUDModeCustomView; // custom view; // you can set the corresponding image; successHUD. customView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ success]; successHUD. removeFromSuperViewOnHide = true; [successHUD hide: true afterDelay: 1];} failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {NSLog (@ failure: % @, error ); hud. removeFromSuperViewOnHide = true; [hud hide: true afterDelay: 0]; // display the failure prompt; MBProgressHUD * failHUD = [MBProgressHUD showHUDAddedTo: self. view animated: true]; failHUD. labelText = @ loading failed; failHUD. mode = MBProgressHUDModeCustomView; failHUD. customView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ error]; failHUD. removeFromSuperViewOnHide = true; [failHUD hide: true afterDelay: 1] ;}];}

(2) The display effect is as follows:

 

Loading]

.

[Loaded successfully]

.

 

[Loading failed]

.

 

It can be seen that using the default HUD requires a lot of code. If you are interested, you can encapsulate it yourself. This greatly simplifies the amount of code.

 

 

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.