TextButtonTableViewCell.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // TextButtonTableViewCell.swift
  3. // LoopKitUI
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import UIKit
  8. open class TextButtonTableViewCell: LoadingTableViewCell {
  9. override public init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  10. super.init(style: .default, reuseIdentifier: reuseIdentifier)
  11. textLabel?.tintAdjustmentMode = .automatic
  12. textLabel?.textColor = tintColor
  13. }
  14. required public init?(coder aDecoder: NSCoder) {
  15. super.init(coder: aDecoder)
  16. }
  17. public var isEnabled = true {
  18. didSet {
  19. tintAdjustmentMode = isEnabled ? .normal : .dimmed
  20. selectionStyle = isEnabled ? .default : .none
  21. }
  22. }
  23. open override func tintColorDidChange() {
  24. super.tintColorDidChange()
  25. textLabel?.textColor = tintColor
  26. }
  27. open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
  28. super.traitCollectionDidChange(previousTraitCollection)
  29. textLabel?.textColor = tintColor
  30. }
  31. open override func prepareForReuse() {
  32. super.prepareForReuse()
  33. textLabel?.textAlignment = .natural
  34. tintColor = nil
  35. isEnabled = true
  36. }
  37. }