NCEmptyDataSet.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // NCEmptyDataSet.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 19/10/2020.
  6. // Copyright © 2020 Marino Faggiana. All rights reserved.
  7. //
  8. import Foundation
  9. class NCEmptyDataSet: NSObject {
  10. var emptyView: NCEmptyView?
  11. var collectionView: UICollectionView?
  12. init(collectionView: UICollectionView, image: UIImage?, title: String, description: String) {
  13. super.init()
  14. self.collectionView = collectionView
  15. if let emptyView = UINib(nibName: "NCEmptyView", bundle: nil).instantiate(withOwner: self, options: nil).first as? NCEmptyView {
  16. self.emptyView = emptyView
  17. emptyView.frame = CGRect(x:0, y: 0, width:300, height:300)
  18. //emptyView.isHidden = true
  19. emptyView.translatesAutoresizingMaskIntoConstraints = false
  20. emptyView.emptyImage.image = image
  21. emptyView.emptyTtle.text = NSLocalizedString(title, comment: "")
  22. emptyView.emptyDescription.text = NSLocalizedString(description, comment: "")
  23. collectionView.addSubview(emptyView)
  24. emptyView.centerXAnchor.constraint(equalTo: collectionView.centerXAnchor, constant: 0).isActive = true
  25. emptyView.topAnchor.constraint(equalTo: collectionView.topAnchor).isActive = true
  26. emptyView.layoutIfNeeded()
  27. }
  28. }
  29. func reload() {
  30. let items = collectionView?.numberOfItems(inSection: 0)
  31. if items == 0 {
  32. emptyView?.isHidden = false
  33. } else {
  34. //emptyView?.isHidden = true
  35. }
  36. }
  37. }
  38. class NCEmptyView: UIView {
  39. @IBOutlet weak var emptyImage: UIImageView!
  40. @IBOutlet weak var emptyTtle: UILabel!
  41. @IBOutlet weak var emptyDescription: UILabel!
  42. }