KeyboardTeachDialogueCell.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // KeyboardTeachDialogueCell.swift
  3. // AiKeyboard
  4. //
  5. // Created by Destiny on 2025/4/25.
  6. //
  7. import UIKit
  8. import Lottie
  9. class KeyboardTeachDialogueCell: UITableViewCell {
  10. static func reuseIdentifier() -> String {
  11. return "KeyboardTeachDialogueCell"
  12. }
  13. lazy var containerView: UIView = {
  14. let view = UIView(frame: CGRect(x: 0, y: 0, width: KeyboardConst.kb_kScreenW - 84, height: KeyboardTeachView.UX.resultCellHeight))
  15. view.backgroundColor = .white
  16. view.addFourCorner(topLeft: 14, topRight: 18, bottomLeft: 0, bottomRight: 18)
  17. return view
  18. }()
  19. lazy var dialogueLabel: UILabel = {
  20. let label = UILabel()
  21. label.isHidden = true
  22. label.numberOfLines = 0
  23. label.text = "巴拉巴拉小魔仙?"
  24. label.font = .systemFont(ofSize: 12)
  25. label.textColor = .hexStringColor(hexString: "#000000", alpha: 0.8)
  26. label.setLineSpacing(5)
  27. return label
  28. }()
  29. lazy var loadingAnimate: LottieAnimationView = {
  30. let animate = LottieAnimationView(name: "keyboard_dialog_loading")
  31. animate.loopMode = .loop
  32. animate.backgroundColor = .clear
  33. return animate
  34. }()
  35. lazy var loadingLabel: UILabel = {
  36. let label = UILabel()
  37. label.text = "加载中..."
  38. label.font = .systemFont(ofSize: 12)
  39. label.textColor = .hexStringColor(hexString: "#000000", alpha: 0.47)
  40. return label
  41. }()
  42. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  43. super.init(style: style, reuseIdentifier: reuseIdentifier)
  44. self.backgroundColor = .clear
  45. self.contentView.addSubview(containerView)
  46. // containerView.snp.makeConstraints { make in
  47. // make.left.right.top.equalTo(0)
  48. // make.height.equalTo(height)
  49. // }
  50. containerView.addSubview(dialogueLabel)
  51. dialogueLabel.snp.makeConstraints { make in
  52. make.left.equalTo(11)
  53. make.right.equalTo(-10)
  54. make.centerY.equalToSuperview()
  55. }
  56. containerView.addSubview(loadingAnimate)
  57. containerView.addSubview(loadingLabel)
  58. loadingAnimate.snp.makeConstraints { make in
  59. make.size.equalTo(CGSize(width: 14, height: 14))
  60. make.left.equalTo(10)
  61. make.centerY.equalToSuperview()
  62. }
  63. loadingAnimate.play()
  64. loadingLabel.snp.makeConstraints { make in
  65. make.left.equalTo(loadingAnimate.snp.right).offset(8)
  66. make.centerY.equalToSuperview()
  67. }
  68. }
  69. required init?(coder: NSCoder) {
  70. fatalError("init(coder:) has not been implemented")
  71. }
  72. func setLoading(play: Bool) {
  73. if play {
  74. self.dialogueLabel.isHidden = true
  75. self.loadingAnimate.isHidden = false
  76. self.loadingLabel.isHidden = false
  77. self.loadingAnimate.play()
  78. self.containerView.frame = CGRect(x: 0, y: 0, width: KeyboardConst.kb_kScreenW - 84, height: KeyboardTeachView.UX.resultCellHeight)
  79. self.containerView.addFourCorner(topLeft: 14, topRight: 18, bottomLeft: 0, bottomRight: 18)
  80. } else {
  81. self.dialogueLabel.isHidden = false
  82. self.loadingAnimate.isHidden = true
  83. self.loadingLabel.isHidden = true
  84. self.loadingAnimate.pause()
  85. }
  86. }
  87. func config(content: String) {
  88. setLoading(play: false)
  89. self.dialogueLabel.text = content
  90. let height = content.heightAccording(width: KeyboardConst.kb_kScreenW - 105, font: .systemFont(ofSize: 12), lineSpacing: 5) + 16
  91. self.containerView.frame = CGRect(x: 0, y: 0, width: KeyboardConst.kb_kScreenW - 84, height: height)
  92. self.containerView.addFourCorner(topLeft: 14, topRight: 18, bottomLeft: 0, bottomRight: 18)
  93. }
  94. }