Skip to content

Instantly share code, notes, and snippets.

@dnaismyth
Created October 22, 2017 17:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnaismyth/e97c1fbe389e3568babe3679cdd8f84e to your computer and use it in GitHub Desktop.
Save dnaismyth/e97c1fbe389e3568babe3679cdd8f84e to your computer and use it in GitHub Desktop.
DZNEmptyDataSet Example
import UIKit
import DZNEmptyDataSet
class ViewController: UIViewController, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
@IBOutlet var tableView: UITableView!
let tungsten: UIColor = UIColor(red:0.20, green:0.20, blue:0.20, alpha:1.0)
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.emptyDataSetSource = self
self.tableView.emptyDataSetDelegate = self
self.tableView.tableFooterView = UIView() // remove empty cells from tableView
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// Add an image to your empty data set
func image(forEmptyDataSet scrollView: UIScrollView!) -> UIImage! {
let image = UIImage(named: "Coffee")?.withRenderingMode(.alwaysTemplate)
scrollView.tintColor = self.tungsten
return image
}
// Add a title to your empty data set
func title(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
let text = "Sorry, nothing found here."
let attribs = [
NSFontAttributeName: UIFont(name: "Helvetica", size: 18.0)!,
NSForegroundColorAttributeName: self.tungsten
]
return NSAttributedString(string: text, attributes: attribs)
}
// Add a description to your empty data set
func description(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
let text = "Please check back at another time and we might have something more."
let para = NSMutableParagraphStyle()
para.lineBreakMode = NSLineBreakMode.byWordWrapping
para.alignment = NSTextAlignment.center
let attribs = [
NSFontAttributeName: UIFont(name: "Helvetica", size: 14.0)!,
NSForegroundColorAttributeName: UIColor.lightGray,
NSParagraphStyleAttributeName: para
]
return NSAttributedString(string: text, attributes: attribs)
}
// Set the background color of your empty data set
func backgroundColor(forEmptyDataSet scrollView: UIScrollView!) -> UIColor! {
return UIColor(red:0.96, green:0.96, blue:0.96, alpha:1.0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment