Advertisement
Guest User

Kpiheader

a guest
Nov 14th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. // SAP Fiori for iOS Mentor
  2. // SAP Cloud Platform SDK for iOS Code Example
  3. // KPI Header
  4. // Copyright © 2018 SAP SE or an SAP affiliate company. All rights reserved.
  5.  
  6.  
  7. import SAPFiori
  8. import UIKit
  9.  
  10. class KPIHeaderExample: UITableViewController {
  11.  
  12. var kpiExampleData = [FUIKPIContainer]()
  13.  
  14. override func viewDidLoad() {
  15. super.viewDidLoad()
  16.  
  17. tableView.backgroundColor = UIColor.preferredFioriColor(forStyle: .backgroundBase)
  18. tableView.separatorStyle = .none
  19.  
  20. initExampleData()
  21. setKPIHeader()
  22.  
  23. }
  24.  
  25. private func buildKPIView(items: [FUIKPIViewItem], captionLabelText: String = "", captionLabelLines: Int = 1, colorScheme: FUIBackgroundColorScheme = .light, isEnabled: Bool = true) -> FUIKPIView {
  26. let kpiView = FUIKPIView()
  27. kpiView.items = items
  28. kpiView.captionlabel.text = captionLabelText
  29. kpiView.captionlabel.numberOfLines = captionLabelLines
  30. kpiView.colorScheme = colorScheme
  31. kpiView.isEnabled = isEnabled
  32.  
  33. return kpiView
  34. }
  35.  
  36. private func setKPIHeader() {
  37. let kpiHeader = FUIKPIHeader()
  38. var kpiItems = [FUIKPIContainer]()
  39.  
  40. for index in 0...1 {
  41. kpiItems.append(kpiExampleData[index])
  42. }
  43.  
  44. kpiHeader.items = kpiItems
  45. tableView.tableHeaderView = kpiHeader
  46. }
  47.  
  48. private func initExampleData() {
  49. let kpiView1 = buildKPIView(items: [FUIKPIMetricItem(string: "2")],
  50. captionLabelText: "Customers Assisted",
  51. colorScheme: .dark,
  52. isEnabled: true)
  53.  
  54. let kpiView2 = buildKPIView(items: [FUIKPIMetricItem(string: "5")],
  55. captionLabelText: "Still in Store Waiting for Checkout",
  56. captionLabelLines: 2,
  57. colorScheme: .dark,
  58. isEnabled: true)
  59.  
  60. let kpiView3 = buildKPIView(items: [FUIKPIMetricItem(string: "4")],
  61. captionLabelText: "Orders",
  62. colorScheme: .dark,
  63. isEnabled: true)
  64.  
  65. let kpiView4 = buildKPIView(items: [FUIKPIUnitItem(string: "$"),
  66. FUIKPIMetricItem(string: "294"),
  67. FUIKPIUnitItem(string: "k")],
  68. captionLabelText: "Average Spend per Calendar Year",
  69. captionLabelLines: 2,
  70. colorScheme: .dark,
  71. isEnabled: true)
  72.  
  73. kpiExampleData = [kpiView1, kpiView2, kpiView3, kpiView4]
  74. }
  75. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  76. // return 0 as we display only the header
  77. return 0
  78. }
  79.  
  80. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  81. return UITableViewCell()
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement