CommentInputView.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // CommentInputView.swift
  3. // RainbowPlanet
  4. //
  5. // Created by 南鑫林 on 2019/7/8.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. //
  8. import UIKit
  9. import IQKeyboardManagerSwift
  10. import RxSwift
  11. class CommentInputView: UIView {
  12. let disposeBag = DisposeBag()
  13. typealias CommentInputViewClosure = () -> ()
  14. var commentInputViewClosure :CommentInputViewClosure?
  15. override init(frame: CGRect) {
  16. super.init(frame: frame)
  17. setupViews()
  18. }
  19. required init?(coder aDecoder: NSCoder) {
  20. fatalError("init(coder:) has not been implemented")
  21. }
  22. func setupViews() {
  23. self.backgroundColor = UIColor.white
  24. addSubview(inputTextView)
  25. addSubview(sendButton)
  26. }
  27. lazy var inputTextView: IQTextView = {
  28. let inputTextView = IQTextView(frame: CGRect(x: 14, y: 10, width: kScreenWidth - 14 - 84, height: 30))
  29. inputTextView.backgroundColor = kf0f0f0Color
  30. inputTextView.font = kRegularFont14
  31. inputTextView.layoutManager.allowsNonContiguousLayout = false
  32. inputTextView.enablesReturnKeyAutomatically = true
  33. inputTextView.scrollsToTop = false
  34. inputTextView.textContainerInset = UIEdgeInsets(top: 5, left: 15, bottom: 5, right: 15)
  35. inputTextView.textContainer.lineFragmentPadding = 0
  36. inputTextView.layer.cornerRadius = 14
  37. inputTextView.layer.masksToBounds = true
  38. inputTextView.placeholder = "添加评论...";
  39. inputTextView.tintColor = kThemeColor
  40. inputTextView.isEditable = false
  41. inputTextView.addTapGesture(1, target: self, action: #selector(showKeyBoard))
  42. return inputTextView
  43. }()
  44. lazy var sendButton: UIButton = {
  45. let sendButton = UIButton(type: UIButton.ButtonType.custom)
  46. sendButton.frame = CGRect(x: kScreenWidth - 14 - 60, y: 11, width: 60, height: 28)
  47. sendButton.setTitle("发布", for: UIControl.State.normal)
  48. sendButton.setBackgroundImage(UIImage.imageWithColor(color: kThemeColor), for: UIControl.State.normal)
  49. sendButton.setBackgroundImage(UIImage.imageWithColor(color: kd8d8d8Color), for: UIControl.State.disabled)
  50. sendButton.titleLabel?.font = kRegularFont14
  51. sendButton.layer.cornerRadius = 14;
  52. sendButton.layer.masksToBounds = true
  53. sendButton.isEnabled = false
  54. return sendButton
  55. }()
  56. @objc func showKeyBoard() {
  57. if let commentInputViewClosure = commentInputViewClosure {
  58. commentInputViewClosure()
  59. }
  60. }
  61. }