zoukankan      html  css  js  c++  java
  • swift MBProgressHUD加载gif或者apng的动图

    效果图

    给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,  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
    
  • 相关阅读:
    spring mvc之DispatcherServlet类分析
    python根据操作系统类型调用特定模块
    C#编写windows服务程序
    写在开始前---多端小系统结构
    写在开始前---web异常处理
    java反射
    写在开始前---简单业务分层
    写在开始前---ajax中的会话过期与重新登录
    一个简易的netty udp服务端
    google的python语言规范
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/6638088.html
Copyright © 2011-2022 走看看