Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SAP Fiori for iOS Mentor
- // SAP Cloud Platform SDK for iOS Code Example
- // KPI Header
- // Copyright © 2018 SAP SE or an SAP affiliate company. All rights reserved.
- import SAPFiori
- import UIKit
- class KPIHeaderExample: UITableViewController {
- var kpiExampleData = [FUIKPIContainer]()
- override func viewDidLoad() {
- super.viewDidLoad()
- tableView.backgroundColor = UIColor.preferredFioriColor(forStyle: .backgroundBase)
- tableView.separatorStyle = .none
- initExampleData()
- setKPIHeader()
- }
- private func buildKPIView(items: [FUIKPIViewItem], captionLabelText: String = "", captionLabelLines: Int = 1, colorScheme: FUIBackgroundColorScheme = .light, isEnabled: Bool = true) -> FUIKPIView {
- let kpiView = FUIKPIView()
- kpiView.items = items
- kpiView.captionlabel.text = captionLabelText
- kpiView.captionlabel.numberOfLines = captionLabelLines
- kpiView.colorScheme = colorScheme
- kpiView.isEnabled = isEnabled
- return kpiView
- }
- private func setKPIHeader() {
- let kpiHeader = FUIKPIHeader()
- var kpiItems = [FUIKPIContainer]()
- for index in 0...1 {
- kpiItems.append(kpiExampleData[index])
- }
- kpiHeader.items = kpiItems
- tableView.tableHeaderView = kpiHeader
- }
- private func initExampleData() {
- let kpiView1 = buildKPIView(items: [FUIKPIMetricItem(string: "2")],
- captionLabelText: "Customers Assisted",
- colorScheme: .dark,
- isEnabled: true)
- let kpiView2 = buildKPIView(items: [FUIKPIMetricItem(string: "5")],
- captionLabelText: "Still in Store Waiting for Checkout",
- captionLabelLines: 2,
- colorScheme: .dark,
- isEnabled: true)
- let kpiView3 = buildKPIView(items: [FUIKPIMetricItem(string: "4")],
- captionLabelText: "Orders",
- colorScheme: .dark,
- isEnabled: true)
- let kpiView4 = buildKPIView(items: [FUIKPIUnitItem(string: "$"),
- FUIKPIMetricItem(string: "294"),
- FUIKPIUnitItem(string: "k")],
- captionLabelText: "Average Spend per Calendar Year",
- captionLabelLines: 2,
- colorScheme: .dark,
- isEnabled: true)
- kpiExampleData = [kpiView1, kpiView2, kpiView3, kpiView4]
- }
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- // return 0 as we display only the header
- return 0
- }
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- return UITableViewCell()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement