Skip to content

Instantly share code, notes, and snippets.

@pai911
Created January 25, 2016 05:14
Show Gist options
  • Save pai911/a6e1c3addbfcb52355a7 to your computer and use it in GitHub Desktop.
Save pai911/a6e1c3addbfcb52355a7 to your computer and use it in GitHub Desktop.
Create a simple spinner without using any library
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()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment