Skip to content

Instantly share code, notes, and snippets.

@pai911
Created January 25, 2016 05:14
Show Gist options
  • Select an option

  • Save pai911/a6e1c3addbfcb52355a7 to your computer and use it in GitHub Desktop.

Select an option

Save pai911/a6e1c3addbfcb52355a7 to your computer and use it in GitHub Desktop.

Revisions

  1. pai911 created this gist Jan 25, 2016.
    39 changes: 39 additions & 0 deletions LoadingSpinnerOverlay.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@

    import Foundation


    public class LoadingSpinnerOverlay{

    var overlayView = UIView()
    var activityIndicator = UIActivityIndicatorView()

    class var shared: LoadingSpinnerOverlay {
    struct Static {
    static let instance = LoadingSpinnerOverlay()
    }
    return Static.instance
    }

    public func showOverlayOnView(view: UIView) {

    overlayView.frame = CGRect(x: 0, y: 0, width: 80, height: 80)
    overlayView.center = view.center
    overlayView.backgroundColor = UIColor.grayColor().colorWithAlphaComponent(0.5)
    overlayView.clipsToBounds = true
    overlayView.layer.cornerRadius = 10

    activityIndicator.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
    activityIndicator.activityIndicatorViewStyle = .WhiteLarge
    activityIndicator.center = CGPointMake(overlayView.bounds.width / 2, overlayView.bounds.height / 2)

    overlayView.addSubview(activityIndicator)
    view.addSubview(overlayView)

    activityIndicator.startAnimating()
    }

    public func hideOverlayView() {
    activityIndicator.stopAnimating()
    overlayView.removeFromSuperview()
    }
    }