How to use MBProgressHUD with swift
Updated Answer:
let loadingNotification = MBProgressHUD.showAdded(to: view, animated: true)
loadingNotification.mode = MBProgressHUDMode.indeterminate
loadingNotification.label.text = "Loading"
To dismiss the ProgressHUD:
MBProgressHUD.hideAllHUDs(for: view, animated: true)
MBProgressHUD not working in swift: cannot import and use
Try this:
1) Specify use_frameworks!
in your Podfile
to use frameworks (instead of static libraries).
This is required for adding pods that are written in Swift as dependencies and a good idea in general if your app is written in Swift.
2) Do pod install
This makes sure your project is setup to actually use the above.
3) Add #import <MBProgressHUD/MBProgressHUD.h>
in your bridging header (notice the angle brackets- not quotes) and import MBProgressHUD
in the Swift class that needs to use it.
That is,
MyApp-Bridging-Header.h :
#import <MBProgressHUD/MBProgressHUD.h>
// ... other imports ...
This exposes the Objective-C files to Swift. Angle brackets indicate this is actually importing a framework.
MyViewController.swift :
import UIKit
import MBProgressHUD
// ... other imports...
class MyViewController: UIViewController {
// ... yada yada...
}
This actually imports the dependency for use by your view controller.
MBProgressHud View Customization Not Work In Swift 3 And Not Showing?
Try with this library ACProgressHud-Swift
In xib file whatever view make then customise and use it.
For Show
ACProgressHUD.shared.showHUD(withStatus: “Your Message Name“)
For hide
ACProgressHUD.shared.hideHUD()
Creating Start and Stop Functions for MBProgressHUD
Declare your spinningActivity
as a global variable in your ViewController
. Anytime when a HUD is needed you can do self.spinningActivity = MBProgressHUD.showAdded(to: self.view, animated: true)
. And when you don't need it anymore, self.spinningActivity?.hide()
MBProgressHud with gif image
use latest libraries of MBProgressHUD and SDWebImage for "UIImage+GIF.h" and it is working fine
-(void) showLoadingHUD:(NSString *)title {
[HUD hideAnimated:true];
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.label.text = title;
HUD.bezelView.color = [UIColor clearColor];
UIImageView *imageViewAnimatedGif = [[UIImageView alloc]init];
//The key here is to save the GIF file or URL download directly into a NSData instead of making it a UIImage. Bypassing UIImage will let the GIF file keep the animation.
NSString *filePath = [[NSBundle mainBundle] pathForResource: @"loader" ofType: @"gif"];
NSData *gifData = [NSData dataWithContentsOfFile: filePath];
imageViewAnimatedGif.image = [UIImage sd_animatedGIFWithData:gifData];
HUD.customView = [[UIImageView alloc] initWithImage:imageViewAnimatedGif.image];
CABasicAnimation *rotation;
rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
rotation.fromValue = [NSNumber numberWithFloat:0];
rotation.toValue = [NSNumber numberWithFloat:(2 * M_PI)];
rotation.duration = 0.7f; // Speed
rotation.repeatCount = HUGE_VALF; // Repeat forever. Can be a finite number.
rotation.removedOnCompletion = false;
[HUD.customView.layer addAnimation:rotation forKey:@"Spin"];
HUD.mode = MBProgressHUDModeCustomView;
HUD.contentColor = [UIColor redColor];
[HUD showAnimated:YES];
}
sample loader .gif image:
Related Topics
Debugging Mobile Safari in iOS 8 and iOS 9
Unrecognized Selector Sent to Instance While Archiving Data (Nscoding)
Swift Base64 Decoding Returns Nil
Info.Plist File for React Native iOS App Using Expo Sdk
How to Properly Set Uirequireddevicecapabilities
Detect Whether a Font Is Bold/Italic on iOS
How to Get Selected Text from Uitextfield in Iphone
Open Wifi Settings by "Prefs:Root=Wifi" Failed in iOS 10
How to Loop Video with Avplayerlooper
Ios: Rounded Rectangle with Border Bleeds Color
Difference Between Keychain and Nsuserdefault
Will Apps That Use Telprompt Be Rejected
Coredata Asynchronous Fetch Causes Concurrency Debugger Error
Is -[Uitableview Reloaddata] Asynchronous or Synchronous
iOS 6 Streaming Player Com.Apple.Coremedia.Networkbuffering Bug