How does NSCollectionView draw text without item?

90 views Asked by At

enter image description here

I've seen a lot of APP listing articles in NSCollectionView. When there is no item, there are some hints in the middle of view, such as "no articles", "waiting to add", and so forth.

Do you have any relevant cases to show me how this is accomplished?.

Thank you

1

There are 1 answers

0
Yerken On BEST ANSWER

Try this code:

  func showMessage(_ text: String) {
    let messageLabel = UILabel()
    messageLabel.text = text
    messageLabel.numberOfLines = 0
    messageLabel.textAlignment = .center
    self.collectionView.backgroundView = messageLabel
  }

  func hideMessage() {
    self.collectionView.backgroundView = nil
  }