12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //
- // NCEmptyDataSet.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 19/10/2020.
- // Copyright © 2020 Marino Faggiana. All rights reserved.
- //
- import Foundation
- class NCEmptyDataSet: NSObject {
-
- var emptyView: NCEmptyView?
-
- init(view: UIView, image: UIImage?, title: String, description: String, offset: CGFloat) {
- super.init()
- if let emptyView = UINib(nibName: "NCEmptyView", bundle: nil).instantiate(withOwner: self, options: nil).first as? NCEmptyView {
-
- self.emptyView = emptyView
-
- emptyView.frame = CGRect(x:0, y: 0, width:300, height:300)
- emptyView.isHidden = true
- emptyView.translatesAutoresizingMaskIntoConstraints = false
- emptyView.emptyImage.image = image
- emptyView.emptyTtle.text = NSLocalizedString(title, comment: "")
- emptyView.emptyDescription.text = NSLocalizedString(description, comment: "")
-
- view.addSubview(emptyView)
- let constantY: CGFloat = (view.frame.height - emptyView.frame.height) / 2 - offset
-
- emptyView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
- emptyView.topAnchor.constraint(equalTo: view.topAnchor, constant: constantY).isActive = true
- }
- }
-
- func numberOfItemsInSection(_ numberItems: Int) {
- if numberItems == 0 {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
- self.emptyView?.isHidden = false
- }
- } else {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.0) {
- self.emptyView?.isHidden = true
- }
- }
- }
- }
- class NCEmptyView: UIView {
-
- @IBOutlet weak var emptyImage: UIImageView!
- @IBOutlet weak var emptyTtle: UILabel!
- @IBOutlet weak var emptyDescription: UILabel!
- }
|