 class JHProgressHUD: UIView
 {
     
-    private var backGroundView : UIView?
-    private var progressIndicator : UIActivityIndicatorView?
-    private var titleLabel : UILabel?
-    private var footerLabel : UILabel?
+    fileprivate var backGroundView : UIView?
+    fileprivate var progressIndicator : UIActivityIndicatorView?
+    fileprivate var titleLabel : UILabel?
+    fileprivate var footerLabel : UILabel?
     
     var headerColor : UIColor
     var footerColor : UIColor
     var backGroundColor : UIColor
     var loaderColor : UIColor
-
-    class var sharedHUD : JHProgressHUD {
-    struct Static {
-        static var instance : JHProgressHUD?
-        static var token : dispatch_once_t = 0
-        }
-        dispatch_once(&Static.token) {
-            Static.instance = JHProgressHUD()
-        }
-        return Static.instance!
-    }
+    
+    static let sharedHUD = JHProgressHUD()
     
     init()
     {
         //Initialising Code
-        headerColor = UIColor.whiteColor()
-        footerColor = UIColor.whiteColor()
-        backGroundColor = UIColor.blackColor()
-        loaderColor = UIColor.whiteColor()
-        super.init(frame: CGRectZero)
-    }
-
+        headerColor = UIColor.white
+        footerColor = UIColor.white
+        backGroundColor = UIColor.black
+        loaderColor = UIColor.white
+        super.init(frame: CGRect.zero)
+    }
+    
     required init(coder aDecoder: NSCoder)
     {
-        headerColor = UIColor.whiteColor()
-        footerColor = UIColor.whiteColor()
-        backGroundColor = UIColor.blackColor()
-        loaderColor = UIColor.whiteColor()
-        super.init(coder: aDecoder)
+        headerColor = UIColor.white
+        footerColor = UIColor.white
+        backGroundColor = UIColor.black
+        loaderColor = UIColor.white
+        super.init(coder: aDecoder)!
     }
     
     override init(frame: CGRect)
     {
-        headerColor = UIColor.whiteColor()
-        footerColor = UIColor.whiteColor()
-        backGroundColor = UIColor.blackColor()
-        loaderColor = UIColor.whiteColor()
+        headerColor = UIColor.white
+        footerColor = UIColor.white
+        backGroundColor = UIColor.black
+        loaderColor = UIColor.white
         super.init(frame: frame)
     }
     
     // MARK: -Public Methods
     
     // Show the loader added to the mentioned view with the provided title and footer texts
-    func showInView(view : UIView, withHeader title : String?, andFooter footer : String?)
+    func showInView(_ view : UIView, withHeader title : String?, andFooter footer : String?)
     {
         self.hide()
         self.frame = view.frame
         setIndicator()
         
-        if title != nil && !isCleanedStringEmpty(title)
+        if title != nil && !isCleanedStringEmpty(title!)
         {
             setTitleLabel(title!)
-            titleLabel!.frame = CGRectMake(0, 0, getLabelSize().width, getLabelSize().height)
-        }
-        if footer != nil && !isCleanedStringEmpty(footer)
+            titleLabel!.frame = CGRect(x: 0, y: 0, width: getLabelSize().width, height: getLabelSize().height)
+        }
+        if footer != nil && !isCleanedStringEmpty(footer!)
         {
             setFooterLabel(footer!)
-            footerLabel!.frame = CGRectMake(0, 0, getLabelSize().width, getLabelSize().height)
+            footerLabel!.frame = CGRect(x: 0, y: 0, width: getLabelSize().width, height: getLabelSize().height)
         }
         setBackGround(self)
-        if title != nil && !isCleanedStringEmpty(title)
+        if title != nil && !isCleanedStringEmpty(title!)
         {
             titleLabel!.frame.origin = getHeaderOrigin(backGroundView!)
             titleLabel?.adjustsFontSizeToFitWidth = true
             backGroundView?.addSubview(titleLabel!)
         }
-        if footer != nil && !isCleanedStringEmpty(footer)
+        if footer != nil && !isCleanedStringEmpty(footer!)
         {
             footerLabel!.frame.origin = getFooterOrigin(backGroundView!)
             footerLabel?.adjustsFontSizeToFitWidth = true

    }
    
    // Show the loader added to the mentioned window with the provided title and footer texts
    func showInWindow(window : UIWindow, withHeader title : String?, andFooter footer : String?)
    {
        self.showInView(window, withHeader: title, andFooter: footer)
    }
    
    // Show the loader added to the mentioned view with no title and footer texts
    func showInView(view : UIView)
    {
        self.showInView(view, withHeader: nil, andFooter: nil)
    }
    
    // Show the loader added to the mentioned window with no title and footer texts
    func showInWindow(window : UIWindow)
    {
        self.showInView(window, withHeader: nil, andFooter: nil)
    }

        footerLabel = UILabel()
        footerLabel?.text = text
        footerLabel?.textColor = footerColor
        footerLabel?.textAlignment = .center
    }
    
    // MARK: -Get Frame
    
    fileprivate func getBackGroundFrame(_ view : UIView) -> CGRect
    {
        let sideMargin:CGFloat = 20.0
        var side = progressIndicator!.frame.height + sideMargin
        if titleLabel?.text != nil && !isCleanedStringEmpty((titleLabel?.text)!)
        {
            side = progressIndicator!.frame.height + titleLabel!.frame.width
        }
        else if (footerLabel?.text != nil && !isCleanedStringEmpty((footerLabel?.text)!))
        {
            side = progressIndicator!.frame.height + footerLabel!.frame.width
        }
        let originX = view.center.x - (side/2)
        let originY = view.center.y - (side/2)
        return CGRect(x: originX, y: originY, width: side, height: side)
    }
    
    // MARK: Get Size
    
    fileprivate func getLabelSize() -> CGSize
    {
        let width = progressIndicator!.frame.width * 3
        let height = progressIndicator!.frame.height / 1.5
        return CGSize(width: width, height: height)
    }
    
    // MARK: -Get Origin
    
    fileprivate func getIndicatorOrigin(_ view : UIView, activityIndicatorView indicator : UIActivityIndicatorView) -> CGPoint
    {
        let side = indicator.frame.size.height
        let originX = (view.bounds.width/2) - (side/2)
        let originY = (view.bounds.height/2) - (side/2)
        return CGPoint(x: originX, y: originY)
    }
    
    fileprivate func getHeaderOrigin(_ view : UIView) -> CGPoint
    {
        let width = titleLabel!.frame.size.width
        let originX = (view.bounds.width/2) - (width/2)
        return CGPoint(x: originX, y: 1)
    }
    
    fileprivate func getFooterOrigin(_ view : UIView) -> CGPoint
    {
        let width = footerLabel!.frame.width
        let height = footerLabel!.frame.height
        let originX = (view.bounds.width/2) - (width/2)
        let originY = view.frame.height - (height + 1)
        return CGPoint(x: originX, y: originY)
    }
    
    fileprivate func isCleanedStringEmpty(_ string: String) -> Bool
    {
        let cleanString = string.trimmingCharacters(in: .whitespacesAndNewlines)
        return cleanString.isEmpty
    }
    
    // MARK: -Set Font
    func boldFontWithFont(_ font : UIFont?) -> UIFont
    {
        let fontDescriptor : UIFontDescriptor = font!.fontDescriptor.withSymbolicTraits(.traitBold)!
        return UIFont(descriptor: fontDescriptor, size: 0)
    }
    
    /*
     // Only override drawRect: if you perform custom drawing.
     // An empty implementation adversely affects performance during animation.
     override func drawRect(rect: CGRect)
     {
     // Drawing code
     }
     */
    
}
