Button.swift 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // Button.swift
  3. // ResetTransmitter
  4. //
  5. // Copyright © 2018 LoopKit Authors. All rights reserved.
  6. //
  7. import UIKit
  8. class Button: UIButton {
  9. required init?(coder aDecoder: NSCoder) {
  10. super.init(coder: aDecoder)
  11. }
  12. override func awakeFromNib() {
  13. super.awakeFromNib()
  14. backgroundColor = tintColor
  15. layer.cornerRadius = 6
  16. titleLabel?.adjustsFontForContentSizeCategory = true
  17. contentEdgeInsets.top = 14
  18. contentEdgeInsets.bottom = 14
  19. setTitleColor(.white, for: .normal)
  20. }
  21. override func tintColorDidChange() {
  22. super.tintColorDidChange()
  23. backgroundColor = tintColor
  24. }
  25. override func prepareForInterfaceBuilder() {
  26. super.prepareForInterfaceBuilder()
  27. tintColor = .blue
  28. tintColorDidChange()
  29. }
  30. override var isHighlighted: Bool {
  31. didSet {
  32. alpha = isHighlighted ? 0.5 : 1
  33. }
  34. }
  35. override var isEnabled: Bool {
  36. didSet {
  37. tintAdjustmentMode = isEnabled ? .automatic : .dimmed
  38. }
  39. }
  40. }