OOUIDownButtonTextField.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // OOUIDownButtonTextField.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/9/11.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. protocol OOUIDownButtonTextFieldDelegate:class {
  10. func viewButtonClicked(_ textField:OOUIDownButtonTextField,_ sender:OOTimerButton)
  11. }
  12. @IBDesignable
  13. class OOUIDownButtonTextField: OOUITextField {
  14. //按钮文字
  15. @IBInspectable open var buttonTitle:String = L10n.Login.getVarificationCode
  16. //倒计时时长
  17. @IBInspectable open var countDown = 60
  18. //按钮文字颜色
  19. @IBInspectable open var buttonTitleColor:UIColor = O2ThemeManager.color(for: "Base.base_color")!
  20. //标签文本颜色
  21. @IBInspectable open var labelTextColor:UIColor = UIColor.hexInt(0x999999)
  22. public var downButton:OOTimerButton?
  23. var buttonDelegate:OOUIDownButtonTextFieldDelegate?
  24. required init?(coder aDecoder: NSCoder) {
  25. super.init(coder: aDecoder)
  26. }
  27. override init(frame: CGRect) {
  28. super.init(frame: frame)
  29. }
  30. override func awakeFromNib() {
  31. super.awakeFromNib()
  32. rightViewMode = .always
  33. //竖线
  34. let vLineView = UIView(frame:CGRect(x: 0, y: 12.5, width: 1, height: 25))
  35. vLineView.backgroundColor = UIColor.hexInt(0xDEDEDE)
  36. downButton = OOTimerButton(countDown, buttonTitle, buttonTitleColor, labelTextColor)
  37. downButton?.frame = CGRect(x: 0, y: 0, width: 100, height: 50)
  38. downButton?.addSubview(vLineView)
  39. downButton?.addTarget(self, action: #selector(downCountClick(_:)), for: .touchUpInside)
  40. rightView = downButton
  41. }
  42. open func themeUpdate(buttonTitleColor: UIColor) {
  43. self.buttonTitleColor = buttonTitleColor
  44. let dbtn = self.rightView as? OOTimerButton
  45. dbtn?.theme_setButtonTextColor(buttonTextColor: buttonTitleColor)
  46. }
  47. @objc func downCountClick(_ sender:OOTimerButton){
  48. sender.startTiming()
  49. guard let btnDelegate = buttonDelegate else {
  50. return
  51. }
  52. btnDelegate.viewButtonClicked(self, sender)
  53. }
  54. override func layoutSubviews() {
  55. super.layoutSubviews()
  56. }
  57. func stopTimerButton() {
  58. downButton?.stopTiming()
  59. }
  60. }