0

My app is a tweak app running in SpringBoard, in which I want to use MBProgressHUD, but it need to specify a view to add to, so how can I get the font most view of the whole iOS?

I should do like that:

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:fronMostView animated:YES];
hud.mode = MBProgressHUDModeText;
hud.labelText = [Localization localize:@"Finished!"];
[hud hide:YES afterDelay:1];
Suge
  • 2,808
  • 3
  • 48
  • 79

2 Answers2

0

The best place to add this view is AppDelegate. Add view in to appDelegate window will show to top front for whole application. Also it remains on top until you hide or remove this view from appDelegate window.

Create a global object of MBProgressHUD in AppDelegate class and create show/hide methods.

Call this methods respectively for your convenience use.

For Example:

@property (nonatomic, strong)  MBProgressHUD   *hud;

- (void) showProgress:(NSString *)message {

    // Create a loading view
    if (!self.hud) {
        _hud = [MBProgressHUD showHUDAddedTo:fronMostView animated:YES];
        self.hud.mode = MBProgressHUDModeText;

        // Add Progress to window.
       [self.window addSubview:self.hud];
    }

    self.hud.hidden = NO;
    self.hud.labelText = [Localization localize:message];
}


- (void) hideLoadingMessage {
    self.hud.labelText = [Localization localize:@"Finished!"];
    [self.hud hide:YES afterDelay:1];
}
Kampai
  • 22,848
  • 21
  • 95
  • 95
  • Thank you, but my tweak app is running at `SpringBoard`, where I can't find the `AppDelegate `. – Suge Jan 12 '15 at 08:29
0

try

UIWindow* window = [[UIApplication sharedApplication] keyWindow];

or

UIWindow *window = [UIApplication sharedApplication].windows.lastObject;

Then

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];

Here is a topic about this, maybe it'll be useful.

Community
  • 1
  • 1
ChildhoodAndy
  • 436
  • 3
  • 11
  • Thank you, but it doesn't work for me, because my tweak app is running inside `SpringBoard`. – Suge Jan 12 '15 at 08:30