Created
January 23, 2020 02:38
-
-
Save mrugeshtank/b14a3f00bf45d865667166136e085a6f to your computer and use it in GitHub Desktop.
add empty message when there is no data one UITableView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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