PaintingCell.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // PaintingCell.swift
  3. // AIPaint
  4. //
  5. // Created by Fengyu He on 2022/12/1.
  6. //
  7. import UIKit
  8. import SnapKit
  9. class PaintingCell: UITableViewCell {
  10. var paintingView: UIImageView?
  11. var createTime: UILabel?
  12. var sessionHash: UILabel?
  13. var prompt: UILabel?
  14. var negativePrompt: UILabel?
  15. required init?(coder: NSCoder) {
  16. super.init(coder: coder)
  17. }
  18. override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  19. super.init(style: style, reuseIdentifier: reuseIdentifier)
  20. setUpUI()
  21. }
  22. func setUpUI() {
  23. paintingView = UIImageView()
  24. createTime = {
  25. var label = UILabel()
  26. label.font = UIFont.systemFont(ofSize: 15)
  27. label.textAlignment = .left
  28. label.textColor = .systemGray2
  29. return label
  30. }()
  31. sessionHash = {
  32. var label = UILabel()
  33. label.font = UIFont.systemFont(ofSize: 15)
  34. label.textAlignment = .left
  35. label.textColor = .systemGray2
  36. return label
  37. }()
  38. prompt = {
  39. var label = UILabel()
  40. label.font = UIFont.systemFont(ofSize: 15)
  41. label.textAlignment = .left
  42. label.textColor = .systemGray2
  43. return label
  44. }()
  45. negativePrompt = {
  46. var label = UILabel()
  47. label.font = UIFont.systemFont(ofSize: 15)
  48. label.textAlignment = .left
  49. label.textColor = .systemGray2
  50. return label
  51. }()
  52. self.addSubview(paintingView!)
  53. self.addSubview(createTime!)
  54. self.addSubview(sessionHash!)
  55. self.addSubview(prompt!)
  56. self.addSubview(negativePrompt!)
  57. paintingView!.snp.makeConstraints { (make) in
  58. make.centerY.equalTo(self.snp.centerY)
  59. make.left.equalTo(self.snp.left).offset(5)
  60. make.height.equalTo(self.snp.height).multipliedBy(0.9)
  61. make.width.equalTo(self.snp.height).multipliedBy(0.9)
  62. }
  63. prompt!.snp.makeConstraints { (make) in
  64. make.top.equalTo(self.snp.top).offset(5)
  65. make.left.equalTo(paintingView!.snp.right).offset(5)
  66. make.height.equalTo(self.snp.height).multipliedBy(0.2)
  67. make.right.equalTo(self.snp.right).offset(-5)
  68. }
  69. sessionHash!.snp.makeConstraints { (make) in
  70. make.top.equalTo(prompt!.snp.bottom).offset(5)
  71. make.left.equalTo(paintingView!.snp.right).offset(5)
  72. make.height.equalTo(self.snp.height).multipliedBy(0.2)
  73. make.right.equalTo(self.snp.right).offset(-5)
  74. }
  75. }
  76. func setValueForCell(painting: Painting) {
  77. if painting.image == nil {
  78. paintingView?.image = UIImage(named: "404.jpeg")
  79. } else {
  80. paintingView?.image = UIImage(data: painting.image!)
  81. }
  82. prompt?.text = painting.prompt
  83. sessionHash?.text = painting.session_hash
  84. }
  85. }