dhaval shah
dhaval shah

Reputation: 4549

Swift, Add a navigation controller in custom activity indicator

My Custom Activity indicator is not overlapping Navigation controller.

Below is my code

     func showActivityIndicator(uiView: UIView) {
        container.frame = uiView.frame
        container.center = uiView.center
        container.backgroundColor = UIColorFromHex(0xffffff, alpha: 0.1)

         var loadingView: UIView = UIView()
         loadingView.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
        loadingView.center = uiView.center
        loadingView.backgroundColor = UIColorFromHex(0x444444, alpha: 0.5)
        loadingView.clipsToBounds = true
        loadingView.layer.cornerRadius = 10

        var imageData = NSData(contentsOfURL: NSBundle.mainBundle()
        .URLForResource("synch-loader", withExtension: "gif")!)
        let try = UIImage.animatedImageWithData(imageData!)
        var imageView = UIImageView(image: try)

        imageView.center = uiView.center
        imageView.frame = CGRect(x: uiView.frame.width/4, y: uiView.frame.height/2, width: 500, height: 15)

        loadingView.addSubview(imageView)
        container.addSubview(loadingView)
        uiView.addSubview(container)
        actInd.startAnimating()

    }

    func navigationHandling()
     {
              if self.navigationController != nil {
             self.navigationController?.navigationBar.tintColor = utility.uicolorFromHex(0x70B420)
            self.navigationController?.navigationBar.barTintColor = utility.uicolorFromHex(0x70B420)
           self.navigationController?.navigationBarHidden = false
            self.navigationItem.hidesBackButton = true

    }
         sortingBtn = UIBarButtonItem(image: sortingImg,  style: UIBarButtonItemStyle.Done, target: self, action: Selector("sortingPressed:"))

          menuBtn = UIBarButtonItem(image: menuImg,  style: UIBarButtonItemStyle.Plain, target: self, action : nil)
          sortingBtn.tintColor = UIColor.whiteColor()
          menuBtn.tintColor = UIColor.whiteColor()
          var buttons : NSArray = [menuBtn,sortingBtn]
          self.navigationItem.rightBarButtonItems = buttons as [AnyObject]
         self.navigationItem.setRightBarButtonItems([menuBtn,sortingBtn], animated: true)
          networkLabel.hidden = true

}

I just want to overlap the view on navigation controller so that it don't looks ugly.

I appreciate help!

Upvotes: 0

Views: 631

Answers (2)

Rasputin
Rasputin

Reputation: 487

let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
let window = appDelegate?.window
window.addSubview("yourActivityIndicator")

Here add the activity indicator to the window, or pass the window in as the view.

let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate
let window = appDelegate?.window
showActivityIndicator(window)

Upvotes: 1

Viton
Viton

Reputation: 67

The uiView you're passing as parameter to this method

func showActivityIndicator(uiView: UIView)

is your ViewController's view or your UINavigationController's view? Because if it's your UIViewController's view your custom loading will take it's size and origin, that is under your NavigationBar

Upvotes: 0

Related Questions