OOUIDownButtonTextField.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 = "发送验证码"
  16. //倒计时时长
  17. @IBInspectable open var countDown = 60
  18. //按钮文字颜色
  19. @IBInspectable open var buttonTitleColor:UIColor = UIColor.hexInt(0xFB4747)
  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. @objc func downCountClick(_ sender:OOTimerButton){
  43. sender.startTiming()
  44. guard let btnDelegate = buttonDelegate else {
  45. return
  46. }
  47. btnDelegate.viewButtonClicked(self, sender)
  48. }
  49. override func layoutSubviews() {
  50. super.layoutSubviews()
  51. }
  52. func stopTimerButton() {
  53. downButton?.stopTiming()
  54. }
  55. }