Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mrugeshtank
Created January 23, 2020 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrugeshtank/b14a3f00bf45d865667166136e085a6f to your computer and use it in GitHub Desktop.
Save mrugeshtank/b14a3f00bf45d865667166136e085a6f to your computer and use it in GitHub Desktop.
add empty message when there is no data one UITableView
extension UITableView {
func setEmptyMessage(_ message: String) {
let messageLabel = UILabel(frame: CGRect(x: 0, y: 0, width: self.bounds.size.width, height: self.bounds.size.height))
messageLabel.text = message
messageLabel.textColor = .black
messageLabel.numberOfLines = 0;
messageLabel.textAlignment = .center;
messageLabel.font = UIFont.preferredFont(forTextStyle: .title3)
messageLabel.sizeToFit()
self.backgroundView = messageLabel;
}
func restore() {
self.backgroundView = nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment