TarifSertifikatCell.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // TarifSertifikatCell.swift
  3. // Sirani
  4. //
  5. // Created by Anhar Solehudin on 31/03/19.
  6. // Copyright © 2019 Anhar Solehudin. All rights reserved.
  7. //
  8. import UIKit
  9. import MaterialComponents.MaterialCards
  10. import SkeletonView
  11. class TarifSertifikatCell: UITableViewCell {
  12. @IBOutlet weak var card: MDCCard!
  13. @IBOutlet weak var lblNamaTarif: UILabel!
  14. @IBOutlet weak var lblBiaya: UILabel!
  15. override func awakeFromNib() {
  16. super.awakeFromNib()
  17. self.selectionStyle = .none
  18. self.backgroundColor = .clear
  19. // Native MDCCard styling
  20. card.cornerRadius = 16
  21. card.setShadowElevation(ShadowElevation(rawValue: 2), for: .normal)
  22. card.setShadowColor(UIColor.black.withAlphaComponent(0.08), for: .normal)
  23. card.layer.borderColor = UIColor(red: 232/255, green: 238/255, blue: 248/255, alpha: 1.0).cgColor
  24. card.layer.borderWidth = 1
  25. // Typography styling
  26. lblNamaTarif.font = UIFont.systemFont(ofSize: 15, weight: .bold)
  27. lblNamaTarif.textColor = UIColor.siraniTextPrimary
  28. lblBiaya.font = UIFont.systemFont(ofSize: 15, weight: .bold)
  29. lblBiaya.textColor = UIColor.siraniPrimaryBlue
  30. self.isSkeletonable = true
  31. card.isSkeletonable = true
  32. lblNamaTarif.isSkeletonable = true
  33. lblBiaya.isSkeletonable = true
  34. }
  35. func updateViews(tarifSertifikat: TarifSertifikat) {
  36. card.isInteractable = false
  37. card.isUserInteractionEnabled = false
  38. lblNamaTarif.text = tarifSertifikat.keterangan
  39. if let tarifValue = Double(tarifSertifikat.tarif) {
  40. let formatter = NumberFormatter()
  41. formatter.numberStyle = .currency
  42. formatter.locale = Locale(identifier: "id_ID")
  43. formatter.currencySymbol = "Rp "
  44. formatter.maximumFractionDigits = 0
  45. if let formattedString = formatter.string(from: NSNumber(value: tarifValue)) {
  46. lblBiaya.text = formattedString
  47. } else {
  48. lblBiaya.text = tarifSertifikat.tarif
  49. }
  50. } else {
  51. lblBiaya.text = tarifSertifikat.tarif
  52. }
  53. }
  54. }