Created
January 25, 2016 05:14
-
-
Save pai911/a6e1c3addbfcb52355a7 to your computer and use it in GitHub Desktop.
Create a simple spinner without using any library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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