From 59583a3f4b6f37231a36375e4e88811b4a4f0ed6 Mon Sep 17 00:00:00 2001 From: Hakan Robs Date: Fri, 23 Jun 2017 16:16:54 +0300 Subject: [PATCH 1/2] Create ViewControllerUtilsSwift2.swift Modified for Swift 3 --- swift/ViewControllerUtilsSwift2.swift | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 swift/ViewControllerUtilsSwift2.swift diff --git a/swift/ViewControllerUtilsSwift2.swift b/swift/ViewControllerUtilsSwift2.swift new file mode 100644 index 0000000..ce26863 --- /dev/null +++ b/swift/ViewControllerUtilsSwift2.swift @@ -0,0 +1,54 @@ +// +// ActivityIndicator.swift +// My Smart List +// +// Created by Hakan on 21/06/2017. +// Copyright © 2017 HSmart Tech. All rights reserved. +// +import Foundation +import UIKit + +class ViewControllerUtils { + + var container: UIView = UIView() + var loadingView: UIView = UIView() + var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView() + + func showActivityIndicator(uiView: UIView) { + container.frame = uiView.frame + container.center = uiView.center + container.backgroundColor = UIColorFromHex(rgbValue: 0xffffff, alpha: 0.3) + + loadingView.frame = CGRect(x: 0, y: 0, width: 80, height: 80) + loadingView.center = uiView.center + loadingView.backgroundColor = UIColorFromHex(rgbValue: 0x444444, alpha: 0.7) + loadingView.clipsToBounds = true + loadingView.layer.cornerRadius = 10 + + activityIndicator.frame = CGRect(x: 0, y: 0, width: 40, height: 40) + activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge + activityIndicator.center = CGPoint(x: loadingView.frame.size.width / 2, y:loadingView.frame.size.height / 2) + + + loadingView.addSubview(activityIndicator) + container.addSubview(loadingView) + uiView.addSubview(container) + activityIndicator.startAnimating() + } + + + func hideActivityIndicator(uiView: UIView) { + activityIndicator.stopAnimating() + container.removeFromSuperview() + } + + func UIColorFromHex(rgbValue:UInt32, alpha:Double=1.0)->UIColor { + let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0 + let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0 + let blue = CGFloat(rgbValue & 0xFF)/256.0 + return UIColor(red:red, green:green, blue:blue, alpha:CGFloat(alpha)) + } + +} +// To use it add this file to your project and then first create class -> let v_c:ViewControllerUtils = ViewControllerUtils() +// then call it to show or hide -> v_c.showActivityIndicator(uiView: self.view) or v_c.hideActivityIndicator(uiView: self.view) From f55edc760915caa9ec52370f591c9bdee33389e4 Mon Sep 17 00:00:00 2001 From: Hakan Robs Date: Fri, 23 Jun 2017 16:17:33 +0300 Subject: [PATCH 2/2] Rename ViewControllerUtilsSwift2.swift to ViewControllerUtilsSwift3.swift --- ...ontrollerUtilsSwift2.swift => ViewControllerUtilsSwift3.swift} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename swift/{ViewControllerUtilsSwift2.swift => ViewControllerUtilsSwift3.swift} (100%) diff --git a/swift/ViewControllerUtilsSwift2.swift b/swift/ViewControllerUtilsSwift3.swift similarity index 100% rename from swift/ViewControllerUtilsSwift2.swift rename to swift/ViewControllerUtilsSwift3.swift