iOS development-using Mbprogresshud to increase user experience (ii)

Source: Internet
Author: User

In my previous blog, "iOS development-using Mbprogresshud to add user experience," The main realization of the use of others have been encapsulated Mbprogresshud to load the hint, can be said to be quite convenient. Today we use the native Mbprogresshud third-party repository on GitHub to load hints that are a little more troublesome than others have already encapsulated. The code has been uploaded to: Https://github.com/chenyufeng1991/UseMBProgressHUD. The implementation steps are as follows:

(1) Also use the network request number attribution place to implement. (See note)

-(Ibaction) sourcebuttonpressed: (ID) Sender {//Declaration object; Mbprogresshud *hud = [Mbprogresshud ShowHUDAddedTo:self.view anima  Ted:true];  The text to be displayed; Hud.labeltext = @ "Loading";  Afhttprequestoperationmanager *manager = [Afhttprequestoperationmanager manager];  Manager.responseserializer = [Afhttpresponseserializer serializer]; This is changed to post, you can make a POST request,//Put the parameters to be passed directly into the URL, rather than in the dictionary; [Manager get:@ "http://webservice.webxml.com.cn/WebServices/ Mobilecodews.asmx/getmobilecodeinfo?mobilecode=18888888888&userid= "Parameters:nil success:^ (AFHTTPRequestOp Eration *operation,id responseobject) {nsstring *string = [[NSString alloc] Initwithdata:res         Ponseobject encoding:nsutf8stringencoding];         NSLog (@ "Success:%@", string);         Successful loading, first remove the original HUD; hud.removefromsuperviewonhide = true;         [HUD Hide:true afterdelay:0];         Then a successful prompt is displayed; Mbprogresshud *successhud = [Mbprogresshud showHUDAddedTo:self.view animated:true];Successhud.labeltext = @ "Load succeeded"; Successhud.mode = mbprogresshudmodecustomview;//custom view;//You can set the corresponding picture; successhud.customview = [[Uiimageview         Alloc] Initwithimage:[uiimage imagenamed:@ "Success"];         Successhud.removefromsuperviewonhide = true;       [Successhud hide:true afterdelay:1];         } failure:^ (Afhttprequestoperation *operation,nserror *error) {NSLog (@ "failed:%@", error);         Hud.removefromsuperviewonhide = true;         [HUD Hide:true afterdelay:0];         Display of failed prompts; Mbprogresshud *failhud = [Mbprogresshud showHUDAddedTo:self.view animated:true];         Failhud.labeltext = @ "failed to load";         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"


"Load succeeded"



"Load Failed"



As you can see, using the default HUD requires a lot of code, and if you're more interested, you could encapsulate it yourself. This can greatly simplify the amount of code.



GitHub Home:https://github.com/chenyufeng1991 . Welcome everyone to visit!

iOS development-using Mbprogresshud to increase user experience (ii)

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.