swift MBProgressHUD加载gif或者apng的动图

效果图
950551-20170329095032154-1859193311.gif

给MBProgressHUD添加一个分类(extension)

extension MBProgressHUD {
    
    ///  MBProgressHUD 显示加载gif hud方法
    ///
    /// - parameter view:               hud where to show
    /// - parameter userInterface:      hud userInerface enable  default = true
    /// - parameter animated:           hud show with animation  default = true
    ///
    /// - returns: nil
    class func showGifAdded(to view:UIView!,userInterface:Bool = true,animated:Bool = true){
        //如果是gif可以使用sdwebImage的方法加载本地gif
        let image = UIImage.sd_animatedGIFNamed("loading")
        //如果是apng图片的话,使用YYKit框架中的YYImage加载apng动图
//        let image = YYImage(named: "loading")
//        let giftImgView =  YYAnimatedImageView(frame: CGRect(x: 0, y: 0, width: 80, height: 80))
//        giftImgView.image = image
        let giftImgView = UIImageView(image: image)
        let hud = MBProgressHUD.showAdded(to: view, animated: animated)
        hud?.color = .clear
        hud?.mode = .customView
        //userInteraction用来控制hud加载过程中用户是否可以做拖动点击操作,默认true
        hud?.isUserInteractionEnabled = userInterface
        hud?.customView = giftImgView
    }
}

使用方法:

MBProgressHUD.showGifAdded(to: view, animated: true)   //默认userInterface=true
MBProgressHUD.showGifAdded(to: view, userInterface: false, animated: true) //可以设置userInterface=false

转载于:https://www.cnblogs.com/qqcc1388/p/6638088.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值