Created
March 9, 2020 03:57
-
-
Save brn-andrade/16e3350a90ca82f065c70b10164aecc2 to your computer and use it in GitHub Desktop.
Spinner Swift (UIActivityIndicatorView)
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
// | |
// UIView+Extension.swift | |
// Finish Payment | |
// | |
// Created by Brunno Andrade on 20/01/20. | |
// Copyright © 2020 Brunno Andrade Inc. All rights reserved. | |
// | |
import Foundation | |
import UIKit | |
import SnapKit | |
fileprivate var uiView: UIView? | |
extension UIViewController { | |
func showSpinner() { | |
uiView = UIView(frame: self.view.frame) | |
uiView?.backgroundColor = UIColor.init(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.3) | |
let activity = UIActivityIndicatorView(style: .large) | |
activity.color = .white | |
activity.startAnimating() | |
uiView?.addSubview(activity) | |
self.view.addSubview(uiView!) | |
let viewBackgroundLoading: UIView = UIView(frame: self.view.frame) | |
viewBackgroundLoading.backgroundColor = .black | |
viewBackgroundLoading.alpha = 0.7 | |
viewBackgroundLoading.clipsToBounds = true | |
viewBackgroundLoading.layer.cornerRadius = 10 | |
viewBackgroundLoading.addSubview(activity) | |
uiView?.addSubview(viewBackgroundLoading) | |
activity.startAnimating() | |
activity.snp.makeConstraints { make in | |
make.center.equalToSuperview() | |
} | |
viewBackgroundLoading.snp.makeConstraints { make in | |
make.size.equalTo(CGSize(width: 80, height: 80)) | |
make.center.equalToSuperview() | |
} | |
} | |
func hideSpinner() { | |
uiView?.removeFromSuperview() | |
uiView = nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment