|
@@ -13,28 +13,37 @@ class NCEmpty: NSObject {
|
|
|
var emptyView: NCEmptyView?
|
|
|
var collectioView: UICollectionView?
|
|
|
|
|
|
- init(collectioView: UICollectionView, image: UIImage, title: String, description: String) {
|
|
|
+ init(collectioView: UICollectionView, image: UIImage?, title: String, description: String) {
|
|
|
super.init()
|
|
|
|
|
|
self.collectioView = collectioView
|
|
|
- emptyView = UINib(nibName: "NCEmptyView", bundle: nil).instantiate(withOwner: self, options: nil).first as? NCEmptyView
|
|
|
+ if let emptyView = UINib(nibName: "NCEmptyView", bundle: nil).instantiate(withOwner: self, options: nil).first as? NCEmptyView {
|
|
|
+
|
|
|
+ self.emptyView = emptyView
|
|
|
|
|
|
- emptyView?.emptyImage.image = image
|
|
|
- emptyView?.emptyTtle.text = title
|
|
|
- emptyView?.emptyDescription.text = description
|
|
|
-
|
|
|
- emptyView?.leftAnchor.constraint(equalTo: collectioView.leftAnchor).isActive = true
|
|
|
- emptyView?.rightAnchor.constraint(equalTo: collectioView.rightAnchor).isActive = true
|
|
|
- emptyView?.topAnchor.constraint(equalTo: collectioView.topAnchor).isActive = true
|
|
|
- emptyView?.bottomAnchor.constraint(equalTo: collectioView.bottomAnchor).isActive = true
|
|
|
+ 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: "")
|
|
|
+
|
|
|
+ collectioView.addSubview(emptyView)
|
|
|
+
|
|
|
+ emptyView.centerXAnchor.constraint(equalTo: collectioView.centerXAnchor, constant: 0).isActive = true
|
|
|
+ emptyView.topAnchor.constraint(equalTo: collectioView.topAnchor).isActive = true
|
|
|
+
|
|
|
+ emptyView.layoutIfNeeded()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func reload() {
|
|
|
let items = collectioView?.numberOfItems(inSection: 0)
|
|
|
- if items == 0 && emptyView != nil {
|
|
|
- collectioView?.addSubview(emptyView!)
|
|
|
+ if items == 0 {
|
|
|
+ emptyView?.isHidden = false
|
|
|
} else {
|
|
|
- emptyView!.removeFromSuperview()
|
|
|
+ //emptyView?.isHidden = true
|
|
|
}
|
|
|
}
|
|
|
}
|