CNLiveShopAssociatedGoodsTableViewCell.swift
3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// CNLiveShopAssociatedGoodsTableViewCell.swift
// metaCode
//
// Created by zx on 2023/12/26.
//
import Foundation
let kDSShopAssociatedGoodsTableViewCellID = "kDSShopAssociatedGoodsTableViewCellID"
class CNLiveShopAssociatedGoodsTableViewCell:UITableViewCell{
var model:ShopOrderAssociatedGoodsModel?
var isSelect:Bool = false
var goodsImageView:UIImageView?
var goodsTitleLab:UILabel?
var goodsTypeLab:UILabel?
var goodsPriceLab:UILabel?
var selectImageView:UIImageView?
var line:UIImageView?
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
self.contentView.backgroundColor = .white
self.initUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - initUI
func initUI(){
self.selectionStyle = .none
let goodsImageView = UIImageView()
goodsImageView.clipsToBounds = true
goodsImageView.contentMode = .scaleAspectFill
self.goodsImageView = goodsImageView
self.addSubview(goodsImageView)
let goodsTitleLab = UILabel()
goodsTitleLab.textColor = HexColor("#333333")
goodsTitleLab.font = UIFont.systemFont(ofSize: 15, weight: .regular)
self.goodsTitleLab = goodsTitleLab
self.addSubview(goodsTitleLab)
let goodsTypeLab = UILabel()
goodsTypeLab.textColor = HexColor("#999999")
goodsTypeLab.font = UIFont.systemFont(ofSize: 13, weight: .light)
self.goodsTypeLab = goodsTypeLab
self.addSubview(goodsTypeLab)
let goodsPriceLab = UILabel()
goodsPriceLab.textColor = HexColor("#FF3355")
goodsPriceLab.font = UIFont.systemFont(ofSize: 19, weight: .medium)
self.goodsPriceLab = goodsPriceLab
self.addSubview(goodsPriceLab)
let selectImageView = UIImageView()
selectImageView.clipsToBounds = true
selectImageView.contentMode = .scaleAspectFit
self.selectImageView = selectImageView
self.addSubview(selectImageView)
let line = UIImageView()
line.backgroundColor = HexColor("#e4e4e4")
self.line = line
self.addSubview(line)
}
// MARK: - 赋值
func setModel(model:ShopOrderAssociatedGoodsModel,isSelect:Bool){
self.setModel(model: model, isSelect: isSelect, keyword: "")
}
func setModel(model:ShopOrderAssociatedGoodsModel,isSelect:Bool,keyword:String){
self.model = model
self.isSelect = isSelect
self.goodsImageView?.kf.setImage(with: URL(string: self.model?.simg ?? ""))
let titleAtt = NSMutableAttributedString(string: self.model?.title ?? "")
if let range = self.model!.title!.range(of: keyword) {
titleAtt.addAttribute(.foregroundColor, value:HexColor("#FC1541")! as UIColor, range: NSRange(range, in: self.model!.title!))
self.goodsTitleLab?.attributedText = titleAtt
self.goodsTypeLab?.text = self.model?.ads ?? ""
var price = NSMutableAttributedString(string: String(format: "¥ %@", self.model?.price ?? ""))
price.addAttributes([NSAttributedString.Key.font:Font_13], range: NSRange(location: 0, length: 2))
self.goodsPriceLab?.attributedText = price
if self.isSelect{
self.selectImageView?.image = UIImage(named: "DS_shop_AssGoods_select")
}else{
self.selectImageView?.image = UIImage(named: "DS_shop_AssGoods_noselect")
}
}
}
}