2 // ActivityIndicatorButton.swift
5 // Created by Pawel Dabrowski on 12/06/2018.
6 // Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved.
11 enum ActivityIndicatorButtonState{
17 class ActivityIndicatorButton: UIButton {
19 private var indicatorButtonState: ActivityIndicatorButtonState = .loading
21 private var activityIndicatorView: UIActivityIndicatorView!
22 override init(frame: CGRect) {
23 super.init(frame: frame)
27 required init?(coder aDecoder: NSCoder) {
28 super.init(coder: aDecoder)
33 activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge)
34 activityIndicatorView.hidesWhenStopped = true
35 activityIndicatorView.tintColor = tintColor
36 activityIndicatorView.color = tintColor
38 activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
39 self.addSubview(activityIndicatorView)
40 activityIndicatorView.centerInSuperview()
41 setIndicatorButtonState(state: .loading)
45 func setIndicatorButtonState(state: ActivityIndicatorButtonState){
46 indicatorButtonState = state
51 activityIndicatorView.startAnimating()
52 setImage(nil, for: .normal)
55 activityIndicatorView.stopAnimating()
56 setImage(#imageLiteral(resourceName: "ic_reload"), for: .normal)