123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // PaintingCell.swift
- // AIPaint
- //
- // Created by Fengyu He on 2022/12/1.
- //
- import UIKit
- import SnapKit
- class PaintingCell: UITableViewCell {
- var paintingView: UIImageView?
- var createTime: UILabel?
- var sessionHash: UILabel?
- var prompt: UILabel?
- var negativePrompt: UILabel?
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
- }
-
- override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- setUpUI()
- }
-
- func setUpUI() {
- paintingView = UIImageView()
-
- createTime = {
- var label = UILabel()
- label.font = UIFont.systemFont(ofSize: 15)
- label.textAlignment = .left
- label.textColor = .systemGray2
- return label
- }()
-
- sessionHash = {
- var label = UILabel()
- label.font = UIFont.systemFont(ofSize: 15)
- label.textAlignment = .left
- label.textColor = .systemGray2
- return label
- }()
-
- prompt = {
- var label = UILabel()
- label.font = UIFont.systemFont(ofSize: 15)
- label.textAlignment = .left
- label.textColor = .systemGray2
- return label
- }()
-
- negativePrompt = {
- var label = UILabel()
- label.font = UIFont.systemFont(ofSize: 15)
- label.textAlignment = .left
- label.textColor = .systemGray2
- return label
- }()
-
- self.addSubview(paintingView!)
- self.addSubview(createTime!)
- self.addSubview(sessionHash!)
- self.addSubview(prompt!)
- self.addSubview(negativePrompt!)
-
- paintingView!.snp.makeConstraints { (make) in
- make.centerY.equalTo(self.snp.centerY)
- make.left.equalTo(self.snp.left).offset(5)
- make.height.equalTo(self.snp.height).multipliedBy(0.9)
- make.width.equalTo(self.snp.height).multipliedBy(0.9)
- }
-
- prompt!.snp.makeConstraints { (make) in
- make.top.equalTo(self.snp.top).offset(5)
- make.left.equalTo(paintingView!.snp.right).offset(5)
- make.height.equalTo(self.snp.height).multipliedBy(0.2)
- make.right.equalTo(self.snp.right).offset(-5)
- }
-
- sessionHash!.snp.makeConstraints { (make) in
- make.top.equalTo(prompt!.snp.bottom).offset(5)
- make.left.equalTo(paintingView!.snp.right).offset(5)
- make.height.equalTo(self.snp.height).multipliedBy(0.2)
- make.right.equalTo(self.snp.right).offset(-5)
- }
- }
-
- func setValueForCell(painting: Painting) {
- if painting.image == nil {
- paintingView?.image = UIImage(named: "404.jpeg")
- } else {
- paintingView?.image = UIImage(data: painting.image!)
- }
- prompt?.text = painting.prompt
- sessionHash?.text = painting.session_hash
- }
- }
|