Forked from igordeoliveirasa/gist:78a310f0348fcad9b270
Created
January 20, 2017 06:34
-
-
Save dipkasyap/9fd078dadd3c2f086a437074ec286bcc to your computer and use it in GitHub Desktop.
iOS Loading Overlay View - SWIFT
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
// | |
// LoadingOverlay.swift | |
// app | |
// | |
// Created by Igor de Oliveira Sa on 25/03/15. | |
// Copyright (c) 2015 Igor de Oliveira Sa. All rights reserved. | |
// | |
// Usage: | |
// | |
// # Show Overlay | |
// LoadingOverlay.shared.showOverlay(self.navigationController?.view) | |
// | |
// # Hide Overlay | |
// LoadingOverlay.shared.hideOverlayView() | |
import UIKit | |
import Foundation | |
public class LoadingOverlay{ | |
var overlayView = UIView() | |
var activityIndicator = UIActivityIndicatorView() | |
class var shared: LoadingOverlay { | |
struct Static { | |
static let instance: LoadingOverlay = LoadingOverlay() | |
} | |
return Static.instance | |
} | |
public func showOverlay(view: UIView!) { | |
overlayView = UIView(frame: UIScreen.mainScreen().bounds) | |
overlayView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.5) | |
activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.WhiteLarge) | |
activityIndicator.center = overlayView.center | |
overlayView.addSubview(activityIndicator) | |
activityIndicator.startAnimating() | |
view.addSubview(overlayView) | |
} | |
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