Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Created March 19, 2016 21:56
Show Gist options
  • Save KentarouKanno/4f78b7c41f31cbfbcf95 to your computer and use it in GitHub Desktop.
Save KentarouKanno/4f78b7c41f31cbfbcf95 to your computer and use it in GitHub Desktop.
CustomIndicator

CustomIndicator

// インジケータークラス

import UIKit

class IndicatorView: UIView {

    static var Indicator = UIActivityIndicatorView(activityIndicatorStyle: .WhiteLarge)
    static let baseView  = UIView()

    static func generateBaseView(parentView: UIView) {

        baseView.frame = parentView.bounds
        baseView.backgroundColor = UIColor.blackColor()
        baseView.alpha = 0.7

        Indicator.center = baseView.center
        Indicator.startAnimating()
        baseView.addSubview(Indicator)
    }

    static func showIndicator(parentView: UIView?) {

        if let parentView = parentView {
            generateBaseView(parentView)
            parentView.addSubview(baseView)
        }
    }

    static func hideIndicator() {
        baseView.removeFromSuperview()
    }
}
// 呼び出すところ(NavigationControllerの場合)
IndicatorView.showIndicator(navigationController?.view)

// 呼び出すところ(ViewControllerの場合)
IndicatorView.showIndicator(view)

// 消す時
IndicatorView.hideIndicator()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment