|
| 1 | +// |
| 2 | +// MBProgressHUD.h |
| 3 | +// Version 0.1 |
| 4 | +// Created by Matej Bukovinski on 8.4.09. |
| 5 | +// |
| 6 | + |
| 7 | +// This code is distributed under the terms and conditions of the MIT license. |
| 8 | + |
| 9 | +// Copyright (c) 2009 Matej Bukovinski |
| 10 | +// |
| 11 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | +// of this software and associated documentation files (the "Software"), to deal |
| 13 | +// in the Software without restriction, including without limitation the rights |
| 14 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | +// copies of the Software, and to permit persons to whom the Software is |
| 16 | +// furnished to do so, subject to the following conditions: |
| 17 | +// |
| 18 | +// The above copyright notice and this permission notice shall be included in |
| 19 | +// all copies or substantial portions of the Software. |
| 20 | +// |
| 21 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | +// THE SOFTWARE. |
| 28 | + |
| 29 | +#import <UIKit/UIKit.h> |
| 30 | + |
| 31 | +/** |
| 32 | + * Displays a simple HUD window containing a UIActivityIndicatorView and two optional labels for short messages. |
| 33 | + * |
| 34 | + * This is a simple drop-in class for displaying a progress HUD view similar to Apples private UIProgressHUD class. |
| 35 | + * The MBProgressHUD window spans over the entire space given to it by the initWithFrame constructor and catches all user |
| 36 | + * input on this region, thereby preventing the user operations on components below the view. |
| 37 | + * The HUD itself is drawn centered as a rounded semi-transparent view witch resizes depending on the user specified content. |
| 38 | + * This view supports three modes of operation: |
| 39 | + * - The default mode displays just a UIActivityIndicatorView. |
| 40 | + * - If the labelText property is set and non-empty then a label containing the provided content is placed below the UIActivityIndicatorView. |
| 41 | + * - If also the detailsLabelText property is set then another label is placed below the firs label. |
| 42 | + */ |
| 43 | +@interface MBProgressHUD : UIView { |
| 44 | + |
| 45 | + SEL methodForExecution; |
| 46 | + id targetForExecution; |
| 47 | + id objectForExecution; |
| 48 | + bool useAnimation; |
| 49 | + |
| 50 | + float width; |
| 51 | + float height; |
| 52 | + |
| 53 | + UIActivityIndicatorView *indicator; |
| 54 | + UILabel *label; |
| 55 | + UILabel *detailsLabel; |
| 56 | + |
| 57 | + id delegate; |
| 58 | + NSString *labelText; |
| 59 | + NSString *detailsLabelText; |
| 60 | + float opacity; |
| 61 | + UIFont *labelFont; |
| 62 | + UIFont *detailsLabelFont; |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * A convenience constructor tat initializes the HUD with the window's bounds. |
| 67 | + * Calls the designated constructor with window.bounds as the parameter. |
| 68 | + */ |
| 69 | +- (id)initWithWindow:(UIWindow *)window; |
| 70 | + |
| 71 | +/** |
| 72 | + * The HUD delegate object. If set the delegate will receive hudWasHidden callbacks when the hud was hidden. |
| 73 | + * The delegate should conform to the MBProgressHUDDelegate protocol and implement the hudWasHidden method. |
| 74 | + */ |
| 75 | +@property (assign) id delegate; |
| 76 | + |
| 77 | +/** |
| 78 | + * An optional short message to be displayed below the activity indicator. |
| 79 | + * The HUD is automatically resized to fit the entire text. If the text is too long it will get clipped by displaying "..." at the end. |
| 80 | + * If left unchanged or set to @"", then no message is displayed. |
| 81 | + */ |
| 82 | +@property (copy) NSString *labelText; |
| 83 | + |
| 84 | +/** |
| 85 | + * An optional details message displayed below the labelText message. |
| 86 | + * This message is displayed only if the labelText property is also set and is different from an empty string (@""). |
| 87 | + */ |
| 88 | +@property (copy) NSString *detailsLabelText; |
| 89 | + |
| 90 | +/** |
| 91 | + * The opacity of the hud window. |
| 92 | + * Defaults to 0.9 (90% opacity). |
| 93 | + */ |
| 94 | +@property (assign) float opacity; |
| 95 | + |
| 96 | +/** |
| 97 | + * Font to be used for the main label. |
| 98 | + * Set this property if the default is not adequate. |
| 99 | + */ |
| 100 | +@property (assign) UIFont *labelFont; |
| 101 | + |
| 102 | +/** |
| 103 | + * Font to be used for the details label. |
| 104 | + * Set this property if the default is not adequate. |
| 105 | + */ |
| 106 | +@property (assign) UIFont *detailsLabelFont; |
| 107 | + |
| 108 | +/** |
| 109 | + * Shows the HUD while a background task is executing in a new thread, then hides the HUD. |
| 110 | + * |
| 111 | + * This method also takes care of NSAutoreleasePools so your method does not have to be concerned with setting up a pool. |
| 112 | + * |
| 113 | + * @param method The method to be executed while the HUD is shown. This method will be executed in a new thread. |
| 114 | + * @param target The object that the target method belongs to. |
| 115 | + * @param object An optional object to be passed to the method. |
| 116 | + * @param animated If set to YES the HUD will appear and disappear using a fade animation. |
| 117 | + * If set to NO the HUD will not use animations while appearing and disappearing. |
| 118 | + */ |
| 119 | +- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(bool)animated; |
| 120 | + |
| 121 | +@end |
| 122 | + |
| 123 | + |
| 124 | +/** |
| 125 | + * Defines callback methods for MBProgressHUD delegates. |
| 126 | + */ |
| 127 | +@protocol MBProgressHUDDelegate |
| 128 | + |
| 129 | +/** |
| 130 | + * A callback function that is called after the hud was fully hidden from the screen. |
| 131 | + */ |
| 132 | +- (void)hudWasHidden; |
| 133 | + |
| 134 | +@end |
| 135 | + |
0 commit comments