ZLBaseTableView.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // ZLBaseTableView.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2016/10/20.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import EmptyDataSet_Swift
  10. open class ZLBaseTableView: UITableView {
  11. var showTitle:Bool = true
  12. var showDesc:Bool = false
  13. public var emptyTitle:String = "" {
  14. didSet {
  15. showTitle = true
  16. }
  17. }
  18. public var emptyDesc:String = ""
  19. override init(frame: CGRect, style: UITableView.Style) {
  20. super.init(frame: frame, style: style)
  21. commonInit()
  22. }
  23. required public init?(coder aDecoder: NSCoder) {
  24. super.init(coder: aDecoder)
  25. commonInit()
  26. }
  27. private func commonInit() {
  28. self.emptyDataSetSource = self
  29. self.emptyDataSetDelegate = self
  30. self.tableFooterView = UIView()
  31. }
  32. }
  33. extension ZLBaseTableView:EmptyDataSetSource,EmptyDataSetDelegate{
  34. public func title(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
  35. let text = emptyTitle
  36. let attributes = [NSAttributedString.Key.font:UIFont(name: "PingFangSC-Regular", size: 20.0)!,NSAttributedString.Key.foregroundColor:RGB(108, g: 108, b: 108)]
  37. return NSAttributedString(string: text, attributes: attributes)
  38. }
  39. public func description(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
  40. let text = emptyDesc
  41. let attributes = [NSAttributedString.Key.font:UIFont(name: "PingFangSC-Light", size: 14.0)!,NSAttributedString.Key.foregroundColor:RGB(108, g: 108, b: 108)]
  42. return NSAttributedString(string: text, attributes: attributes)
  43. }
  44. public func image(forEmptyDataSet scrollView: UIScrollView!) -> UIImage! {
  45. return UIImage(named: "emptyStatusIcon")!
  46. }
  47. public func backgroundColor(forEmptyDataSet scrollView: UIScrollView!) -> UIColor! {
  48. return RGB(247, g: 247, b: 247)
  49. }
  50. public func emptyDataSetShouldDisplay(_ scrollView: UIScrollView!) -> Bool {
  51. return showTitle
  52. }
  53. }