説明なし

UIButtonExt.swift 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // UIButtonExt.swift
  3. // ExtensionKit
  4. //
  5. // Created by FFIB on 2017/9/14.
  6. // Copyright © 2017年 FFIB. All rights reserved.
  7. //
  8. import UIKit
  9. extension UIButton {
  10. @IBInspectable
  11. public var normalStatusBackgroundColor: UIColor? {
  12. set {
  13. if let color = newValue {
  14. let img = UIImage.imageWithColor(color)
  15. self.setBackgroundImage(img, for: UIControlState())
  16. } else {
  17. self.setBackgroundImage(nil, for: UIControlState())
  18. }
  19. }
  20. get {
  21. return nil
  22. }
  23. }
  24. @IBInspectable
  25. public var pressedStatusBackgroundColor: UIColor? {
  26. set {
  27. if let color = newValue {
  28. let img = UIImage.imageWithColor(color)
  29. self.setBackgroundImage(img, for: .highlighted)
  30. } else {
  31. self.setBackgroundImage(nil, for: .highlighted)
  32. }
  33. }
  34. get {
  35. return nil
  36. }
  37. }
  38. @IBInspectable
  39. public var disabledStatusBackgroundColor: UIColor? {
  40. set {
  41. if let color = newValue {
  42. let img = UIImage.imageWithColor(color)
  43. self.setBackgroundImage(img, for: .disabled)
  44. } else {
  45. self.setBackgroundImage(nil, for: .disabled)
  46. }
  47. }
  48. get {
  49. return nil
  50. }
  51. }
  52. @IBInspectable
  53. public var selectedStatusBackgroundColor: UIColor? {
  54. set {
  55. if let color = newValue {
  56. let img = UIImage.imageWithColor(color)
  57. self.setBackgroundImage(img, for: .selected)
  58. } else {
  59. self.setBackgroundImage(nil, for: .selected)
  60. }
  61. }
  62. get {
  63. return nil
  64. }
  65. }
  66. }