BKDropDownCell.swift 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // BKDropDownCellTableViewCell.swift
  3. // Bark
  4. //
  5. // Created by huangfeng on 2023/2/9.
  6. // Copyright © 2023 Fin. All rights reserved.
  7. //
  8. import DropDown
  9. import UIKit
  10. class BKDropDownCell: DropDownCell {
  11. @IBOutlet var selectBackgroundView: UIView!
  12. override func awakeFromNib() {
  13. super.awakeFromNib()
  14. self.backgroundColor = BKColor.white
  15. self.selectBackgroundView.layer.cornerRadius = 10
  16. self.selectBackgroundView.clipsToBounds = true
  17. }
  18. override func setSelected(_ selected: Bool, animated: Bool) {
  19. let executeSelection: () -> Void = { [weak self] in
  20. guard let `self` = self else { return }
  21. let selectedBackgroundColor = BKColor.grey.lighten5
  22. if selected {
  23. self.selectBackgroundView.backgroundColor = selectedBackgroundColor
  24. self.optionLabel.textColor = BKColor.grey.darken4
  25. } else {
  26. self.selectBackgroundView.backgroundColor = .clear
  27. self.optionLabel.textColor = BKColor.grey.darken3
  28. }
  29. }
  30. if animated {
  31. UIView.animate(withDuration: 0.3, animations: {
  32. executeSelection()
  33. })
  34. } else {
  35. executeSelection()
  36. }
  37. accessibilityTraits = selected ? .selected : .none
  38. }
  39. }