Can I use gif image instead of default loading indicator? I am using this code so far but not getting any result. Can anyone suggest what is wrong in this code?
#import "UIImage+GIF.h"
-(void) showLoadingHUD:(NSString *)title
{
[self hideLoadingHUD];
if(!HUD){
HUD = [MBProgressHUD showHUDAddedTo:self.window animated:YES];
}
[HUD setColor:[UIColor clearColor]];
UIImageView *imageViewAnimatedGif = [[UIImageView alloc]init];
imageViewAnimatedGif.image= [UIImage sd_animatedGIFNamed:@"martini_glass"];
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.
[HUD.customView.layer addAnimation:rotation forKey:@"Spin"];
HUD.mode = MBProgressHUDModeCustomView;
[HUD show:YES];
}
Swift 3 I have created two functions in Swift. File name is Globle.Swift. After Create a UIApplication.Swift file and put the following extension for getting topViewController
public extension UIApplication {
class func topViewController(_ viewController: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
}
use latest libraries of MBProgressHUD and SDWebImage for "UIImage+GIF.h" and it is working fine
sample loader .gif image:
You can do this by creating a UIImageView that animates a set of images, and then set the customView property of your MBProgressHUD to be that UIImageView.
Here's a tutorial about creating a UIImageView that animates the images: Create Custom Activity Indicator for your iOS App
link to the tutorial
Hope it help...
Yes, you can use gif images instead of default loading...