Swift add UIImage above custom tableView refresh control

25 views Asked by At

I would like to add a UIImage just above a custom table view refresh control.

Im not sure If I should add the image to the tableView.backgroundView or somehow include it in the custom refresh control.

Code:

var nvActivityIndicator : NVActivityIndicatorView?

func configActivityLoader()  {
        
        // Create refresh control and add as subview in your table view.
        tableView.refreshControl = UIRefreshControl()
        //refreshControl.backgroundColor = .red
        tableView.refreshControl!.addTarget(self, action: #selector(refreshWithPull), for: .valueChanged)
        tableView.refreshControl!.tintColor = .clear
        
        // Create NVActivityIndicator view and add as subview inside refresh control
        nvActivityIndicator = NVActivityIndicatorView(frame: tableView.refreshControl!.bounds, type: NVActivityIndicatorType.ballPulse, color: activityLoaderColor.withAlphaComponent(0.45), padding: 50)
        nvActivityIndicator?.backgroundColor = tableView.refreshControl!.backgroundColor
        nvActivityIndicator?.translatesAutoresizingMaskIntoConstraints = false
        
        
        //        let refreshImage = UIImageView()
        //        refreshImage.image = UIImage(named: "satoshi")
        //tableView.refreshControl!.addSubview(refreshImage)
        
        tableView.refreshControl!.addSubview(nvActivityIndicator!)
        
        // Add constraint to auto resize nvActivityIndicator as per refresh control view.
        let nvActivityIndicator_top = NSLayoutConstraint(item: nvActivityIndicator!, attribute: .top, relatedBy: .equal, toItem: tableView.refreshControl, attribute: .top, multiplier: 1, constant: 0)
        let nvActivityIndicator_bottom = NSLayoutConstraint(item: nvActivityIndicator!, attribute: .bottom, relatedBy: .equal, toItem: tableView.refreshControl, attribute: .bottom, multiplier: 1, constant: 0)
        let nvActivityIndicator_leading = NSLayoutConstraint(item: nvActivityIndicator!, attribute: .leading, relatedBy: .equal, toItem: tableView.refreshControl, attribute: .leading, multiplier: 1, constant: 0)
        let nvActivityIndicator_trailing = NSLayoutConstraint(item: nvActivityIndicator!, attribute: .trailing, relatedBy: .equal, toItem: tableView.refreshControl, attribute: .trailing, multiplier: 1, constant: 0)
        
        // Add constrains
        tableView.refreshControl!.addConstraint(nvActivityIndicator_top)
        tableView.refreshControl!.addConstraint(nvActivityIndicator_bottom)
        tableView.refreshControl!.addConstraint(nvActivityIndicator_leading)
        tableView.refreshControl!.addConstraint(nvActivityIndicator_trailing)
        
        
    }

Library Used: NVActivityIndicatorView

GOAL:

                          [image]

                Activity loader under image
0

There are 0 answers