OOBaseUIButton.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // OOBaseUIButton.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/9/11.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. @IBDesignable
  10. class OOBaseUIButton: UIButton {
  11. var disableBackColor:UIColor? {
  12. didSet {
  13. if !self.isEnabled {
  14. self.backgroundColor = disableBackColor
  15. }
  16. }
  17. }
  18. @IBInspectable var layerCornerRadius:Int = 5 {
  19. didSet {
  20. configUI()
  21. }
  22. }
  23. override func awakeFromNib() {
  24. configUI()
  25. }
  26. override func prepareForInterfaceBuilder() {
  27. super.prepareForInterfaceBuilder()
  28. configUI()
  29. }
  30. func configUI(){
  31. if layerCornerRadius >= 0 {
  32. self.layer.cornerRadius = CGFloat(layerCornerRadius)
  33. self.layer.masksToBounds = true
  34. } else {
  35. self.layer.masksToBounds = false
  36. }
  37. }
  38. override init(frame: CGRect) {
  39. super.init(frame: frame)
  40. commonInit()
  41. configUI()
  42. }
  43. required init?(coder aDecoder: NSCoder) {
  44. super.init(coder: aDecoder)
  45. commonInit()
  46. configUI()
  47. }
  48. private func commonInit(){
  49. //默认背景,字体
  50. self.theme_backgroundColor = ThemeColorPicker(keyPath: "Base.base_color")
  51. self.titleLabel?.font = UIFont(name: "PingFangSC-Regular", size: 15)!
  52. self.setTitleColor(UIColor.white, for: .normal)
  53. }
  54. }