MBProgressHUD position at the bottom of the screen

Is there a way to make MBProgressHUD show at the bottom or top of the screen?

I tried to set the frame using [hud setFrame:....]; , initWithFrame and set the center hud property. None of this worked. After checking these methods, I did NSLog (). The values ​​have changed, but the hud was still displayed in the center of the screen.

It should be noted that hud is displayed using UIWindow:

 UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject]; MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES]; hud.mode = MBProgressHUDModeText; hud.labelText = @"some text"; 

This is because the hash is displayed by the background execution unit, so hud can be displayed in any view currently being displayed.

+7
ios mbprogresshud
source share
5 answers

Yes, we can change the display MBProgressHUD of the MBProgressHUD from the center to the bottom or top.

Just add the yOffset property to MBProgressHUD and you will get the exact location that you want.

Using:

 MBProgressHUD *Hud = [[MBProgressHUD alloc] init]; hud.yOffset = 250.0; //For bottom location. 
+16
source share

I had the same problem with SVProgressHUD , I just had to add a new method

 + (void)setOffsetFromCenter:(UIOffset)offset { [self sharedView].offsetFromCenter = offset; } 

and call him when I showed the HUD

 [SVProgressHUD setOffsetFromCenter:UIOffsetMake(0, 120)]; 

The mine just had to go a little lower than the middle of the screen. Try it, it's SingleTon, so it's easier to call the show and delete.

+1
source share

Cannot reposition MBProgressHUD to top or bottom. Pay attention to the link

0
source share

We can change the position of MBProgressHUD with a change in yOffset and xOffset . Below the line of code is at the bottom of the MBProgressHUD at the bottom.

 let hud = MBProgressHUD.showAdded(to: view, animated: true) hud?.mode = .text hud?.labelText = json!["message"] as! String hud?.yOffset = Float(view.frame.size.height*2/5); hud?.removeFromSuperViewOnHide = true hud?.margin = 10.0 hud?.hide(true, afterDelay: 2) 
0
source share

for Swift 4 , modified by hud.offset.x and hud.offset.y

 let hud = MBProgressHUD.showAdded(to: self.view, animated: true) hud.mode = MBProgressHUDMode.annularDeterminate hud.offset.y = 10 hud.offset.x = 10 
0
source share

All Articles