Coder Social home page Coder Social logo

hqhud's Introduction

HQHud

Swift Hud 最简菊花转 方便拓展功能

UIView的extension

    func showHud(isCovered: Bool = false) {
        
        self.hideHud()
        let frame = CGRect(x: 0, y: 0, width: 78, height: 78)
        
        let backVFrame = isCovered == false ? frame : self.frame
        let backV = UIView(frame: backVFrame)
        backV.center = self.center
        backV.tag = 8421
        self.addSubview(backV)
        
        let hudV = UIView(frame: frame)
        hudV.center = CGPoint(x: backV.frame.width/2, y: backV.frame.height/2)
        hudV.layer.cornerRadius = 12
        hudV.backgroundColor = UIColor(red:0, green:0, blue:0, alpha: 0.8)
        backV.addSubview(hudV)
        
        let indicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge)
        indicatorView.frame = CGRect(x: 21, y: 21, width: 36, height: 36)
        indicatorView.startAnimating()
        hudV.addSubview(indicatorView)
        
        hudV.alpha = 0.0
        UIView.animate(withDuration: 0.2, animations: {
            hudV.alpha = 1
        })
    }
    
    func hideHud() {
        
        let backV = self.viewWithTag(8421)
        guard let backv = backV else { return }
        backv.removeFromSuperview()
    }

使用

     @IBAction func showHud(_ sender: UIButton) {
        
        view.showHud()
    }
    
    @IBAction func hideHud(_ sender: UIButton) {
        
        view.hideHud()
    }
    
    @IBAction func showHudCoveredWindow(_ sender: UIButton) {
        
        Hud_Window?.showHud(isCovered: true)
        
        // 5秒消失
        DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
            Hud_Window?.hideHud()
        }
    }
    
    @IBAction func showHudCoveredView(_ sender: UIButton) {
        
        view.showHud(isCovered: true)
    }
    

hqhud's People

Contributors

kheqing avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.