Last active
November 12, 2021 13:45
-
-
Save alimir1/f595a51c3d298ca5080d87694e757920 to your computer and use it in GitHub Desktop.
Activity indicator with loading text label under (written in swift)
This file contains hidden or 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
// | |
// ActivityIndicator.swift | |
// | |
// Created by Ali Mir on 11/17/16. | |
// Copyright © 2016 com.AliMir. All rights reserved. | |
// | |
import UIKit | |
struct ActivityIndicator { | |
let viewForActivityIndicator = UIView() | |
let view: UIView | |
let navigationController: UINavigationController? | |
let tabBarController: UITabBarController? | |
let activityIndicatorView = UIActivityIndicatorView() | |
let loadingTextLabel = UILabel() | |
var navigationBarHeight: CGFloat { return navigationController?.navigationBar.frame.size.height ?? 0.0 } | |
var tabBarHeight: CGFloat { return tabBarController?.tabBar.frame.height ?? 0.0 } | |
func showActivityIndicator() { | |
viewForActivityIndicator.frame = CGRect(x: 0.0, y: 0.0, width: self.view.frame.size.width, height: self.view.frame.size.height) | |
viewForActivityIndicator.backgroundColor = UIColor.white | |
view.addSubview(viewForActivityIndicator) | |
activityIndicatorView.center = CGPoint(x: self.view.frame.size.width / 2.0, y: (self.view.frame.size.height - tabBarHeight - navigationBarHeight) / 2.0) | |
loadingTextLabel.textColor = UIColor.black | |
loadingTextLabel.text = "LOADING" | |
loadingTextLabel.font = UIFont(name: "Avenir Light", size: 10) | |
loadingTextLabel.sizeToFit() | |
loadingTextLabel.center = CGPoint(x: activityIndicatorView.center.x, y: activityIndicatorView.center.y + 30) | |
viewForActivityIndicator.addSubview(loadingTextLabel) | |
activityIndicatorView.hidesWhenStopped = true | |
activityIndicatorView.activityIndicatorViewStyle = .gray | |
viewForActivityIndicator.addSubview(activityIndicatorView) | |
activityIndicatorView.startAnimating() | |
} | |
func stopActivityIndicator() { | |
viewForActivityIndicator.removeFromSuperview() | |
activityIndicatorView.stopAnimating() | |
activityIndicatorView.removeFromSuperview() | |
} | |
} |
let activityIndicator = ActivityIndicator(view:view, navigationController:nil,tabBarController: nil)
activityIndicator.showActivityIndicator()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to call ActivityIndicator in view controller