Skip to content

Instantly share code, notes, and snippets.

@omaarr90
Created October 22, 2018 23:29
Show Gist options
  • Save omaarr90/6b7e0d42374a554e6a3aa949cca69fa5 to your computer and use it in GitHub Desktop.
Save omaarr90/6b7e0d42374a554e6a3aa949cca69fa5 to your computer and use it in GitHub Desktop.
//
// UIButton+Animations.swift
// OneWallet
//
// Created by Omar Alshammari on 25/01/1440 AH.
// Copyright © 1440 Omar Alshammari. All rights reserved.
//
import UIKit
import PureLayout
//protocol UIViewLoadinAnimating {
// var loadingIndicator: UIView {get set}
//
// func startLoadingAnimation()
// func stopLoadingAnimation()
//}
//
//extension UIViewLoadinAnimating {
//
// var loadingIndicator: UIView {
// get {
// return UIActivityIndicatorView(activityIndicatorStyle: .gray)
// }
// set {
// self.loadingIndicator = newValue
// }
// }
//
//}
extension UIButton
{
func startLoadingAnimation() {
//
self.isEnabled = false
let spin = UIActivityIndicatorView(activityIndicatorStyle: .gray)
addSubview(spin)
spin.autoPinEdge(toSuperviewSafeArea: .trailing, withInset: 10.0)
spin.autoPinEdge(toSuperviewSafeArea: .bottom)
spin.autoPinEdge(toSuperviewSafeArea: .top)
spin.autoSetDimension(.width, toSize: 20.0)
spin.isHidden = false
spin.startAnimating()
}
func stopLoadingAnimation() {
//
for view in subviews {
if let spin = view as? UIActivityIndicatorView {
spin.stopAnimating()
spin.isHidden = true
spin.removeFromSuperview()
}
}
self.isEnabled = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment