added iOS source code
[wl-app.git] / iOS / Pods / MBProgressHUD / README.mdown
1 # MBProgressHUD
2
3 [![Build Status](https://travis-ci.org/matej/MBProgressHUD.svg?branch=master)](https://travis-ci.org/matej/MBProgressHUD) [![codecov.io](https://codecov.io/github/matej/MBProgressHUD/coverage.svg?branch=master)](https://codecov.io/github/matej/MBProgressHUD?branch=master)
4  [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) [![CocoaPods compatible](https://img.shields.io/cocoapods/v/MBProgressHUD.svg?style=flat)](https://cocoapods.org/pods/MBProgressHUD) [![License: MIT](https://img.shields.io/cocoapods/l/MBProgressHUD.svg?style=flat)](http://opensource.org/licenses/MIT)
5
6 `MBProgressHUD` is an iOS drop-in class that displays a translucent HUD with an indicator and/or labels while work is being done in a background thread. The HUD is meant as a replacement for the undocumented, private `UIKit` `UIProgressHUD` with some additional features.
7
8 [![](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/1-small.png)](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/1.png)
9 [![](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/2-small.png)](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/2.png)
10 [![](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/3-small.png)](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/3.png)
11 [![](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/4-small.png)](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/4.png)
12 [![](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/5-small.png)](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/5.png)
13 [![](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/6-small.png)](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/6.png)
14 [![](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/7-small.png)](https://raw.githubusercontent.com/wiki/matej/MBProgressHUD/Screenshots/7.png)
15
16 **NOTE:** The class has recently undergone a major rewrite. The old version is available in the [legacy](https://github.com/jdg/MBProgressHUD/tree/legacy) branch, should you need it. 
17
18 ## Requirements
19
20 `MBProgressHUD` works on iOS 6+ and requires ARC to build. It depends on the following Apple frameworks, which should already be included with most Xcode templates:
21
22 * Foundation.framework
23 * UIKit.framework
24 * CoreGraphics.framework
25
26 You will need the latest developer tools in order to build `MBProgressHUD`. Old Xcode versions might work, but compatibility will not be explicitly maintained.
27
28 ## Adding MBProgressHUD to your project
29
30 ### CocoaPods
31
32 [CocoaPods](http://cocoapods.org) is the recommended way to add MBProgressHUD to your project.
33
34 1. Add a pod entry for MBProgressHUD to your Podfile `pod 'MBProgressHUD', '~> 1.1.0'`
35 2. Install the pod(s) by running `pod install`.
36 3. Include MBProgressHUD wherever you need it with `#import "MBProgressHUD.h"`.
37
38 ### Carthage
39
40 1. Add MBProgressHUD to your Cartfile. e.g., `github "jdg/MBProgressHUD" ~> 1.1.0`
41 2. Run `carthage update`
42 3. Follow the rest of the [standard Carthage installation instructions](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to add MBProgressHUD to your project.
43
44 ### Source files
45
46 Alternatively you can directly add the `MBProgressHUD.h` and `MBProgressHUD.m` source files to your project.
47
48 1. Download the [latest code version](https://github.com/matej/MBProgressHUD/archive/master.zip) or add the repository as a git submodule to your git-tracked project.
49 2. Open your project in Xcode, then drag and drop `MBProgressHUD.h` and `MBProgressHUD.m` onto your project (use the "Product Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project.
50 3. Include MBProgressHUD wherever you need it with `#import "MBProgressHUD.h"`.
51
52 ### Static library
53
54 You can also add MBProgressHUD as a static library to your project or workspace.
55
56 1. Download the [latest code version](https://github.com/matej/MBProgressHUD/downloads) or add the repository as a git submodule to your git-tracked project.
57 2. Open your project in Xcode, then drag and drop `MBProgressHUD.xcodeproj` onto your project or workspace (use the "Product Navigator view").
58 3. Select your target and go to the Build phases tab. In the Link Binary With Libraries section select the add button. On the sheet find and add `libMBProgressHUD.a`. You might also need to add `MBProgressHUD` to the Target Dependencies list.
59 4. Include MBProgressHUD wherever you need it with `#import <MBProgressHUD/MBProgressHUD.h>`.
60
61 ## Usage
62
63 The main guideline you need to follow when dealing with MBProgressHUD while running long-running tasks is keeping the main thread work-free, so the UI can be updated promptly. The recommended way of using MBProgressHUD is therefore to set it up on the main thread and then spinning the task, that you want to perform, off onto a new thread.
64
65 ```objective-c
66 [MBProgressHUD showHUDAddedTo:self.view animated:YES];
67 dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
68         // Do something...
69         dispatch_async(dispatch_get_main_queue(), ^{
70                 [MBProgressHUD hideHUDForView:self.view animated:YES];
71         });
72 });
73 ```
74
75 You can add the HUD on any view or window. It is however a good idea to avoid adding the HUD to certain `UIKit` views with complex view hierarchies - like `UITableView` or `UICollectionView`. Those can mutate their subviews in unexpected ways and thereby break HUD display. 
76
77 If you need to configure the HUD you can do this by using the MBProgressHUD reference that showHUDAddedTo:animated: returns.
78
79 ```objective-c
80 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
81 hud.mode = MBProgressHUDModeAnnularDeterminate;
82 hud.label.text = @"Loading";
83 [self doSomethingInBackgroundWithProgressCallback:^(float progress) {
84         hud.progress = progress;
85 } completionCallback:^{
86         [hud hideAnimated:YES];
87 }];
88 ```
89
90 You can also use a `NSProgress` object and MBProgressHUD will update itself when there is progress reported through that object.
91
92 ```objective-c
93 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
94 hud.mode = MBProgressHUDModeAnnularDeterminate;
95 hud.label.text = @"Loading";
96 NSProgress *progress = [self doSomethingInBackgroundCompletion:^{
97         [hud hideAnimated:YES];
98 }];
99 hud.progressObject = progress;
100 ```
101
102 Keep in mind that UI updates, inclining calls to MBProgressHUD should always be done on the main thread.
103
104 If you need to run your long-running task in the main thread, you should perform it with a slight delay, so UIKit will have enough time to update the UI (i.e., draw the HUD) before you block the main thread with your task.
105
106 ```objective-c
107 [MBProgressHUD showHUDAddedTo:self.view animated:YES];
108 dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC);
109 dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
110         // Do something...
111         [MBProgressHUD hideHUDForView:self.view animated:YES];
112 });
113 ```
114
115 You should be aware that any HUD updates issued inside the above block won't be displayed until the block completes.
116
117 For more examples, including how to use MBProgressHUD with asynchronous operations such as NSURLConnection, take a look at the bundled demo project. Extensive API documentation is provided in the header file (MBProgressHUD.h).
118
119
120 ## License
121
122 This code is distributed under the terms and conditions of the [MIT license](LICENSE).
123
124 ## Change-log
125
126 A brief summary of each MBProgressHUD release can be found in the [CHANGELOG](CHANGELOG.mdown).