JLChen
2021-04-30 a5247b61d585627a1a7b1e1f35f34de9f0af9fba
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
//  Copyright © 2018 dahua. All rights reserved.
//
 
import UIKit
 
@objc public class DHDetailNormalCell: UITableViewCell, IDHTableViewCell {
    
    @IBOutlet public weak var titleLbl: UILabel!
    @IBOutlet public weak var rightLbl: UILabel!
    @IBOutlet public weak var rightArrow: UIImageView!
    @IBOutlet public weak var loadingView: DHActivityIndicatorView!
    @IBOutlet public weak var redDot: UIView!
    @IBOutlet public weak var descriptLbl: UILabel!
    @IBOutlet public weak var leftImageView: UIImageView!
    @IBOutlet public weak var lineView: UIView!
    @IBOutlet public var dotImgV: UIImageView!
    
    override public func awakeFromNib() {
        super.awakeFromNib()
        if let loadView = loadingView {
            loadView.backgroundColor = UIColor.clear
        }
        if let desLabel = descriptLbl {
            desLabel.backgroundColor = UIColor.dhcolor_c7()
            desLabel.text = ""
            desLabel.textColor = UIColor.dhcolor_c5()
            desLabel.font = UIFont.dhFont_t6()
        }
        if let titleLabel = titleLbl {
            titleLabel.textColor = UIColor.dhcolor_c2()
        }
        if let rightLabel = rightLbl {
            rightLabel.textColor = UIColor.dhcolor_c5()
        }
        if let rDot = redDot {
            rDot.lc_setRound()
            rDot.backgroundColor = UIColor.dhcolor_c12()
        }
        if let leftImg = leftImageView {
            leftImg.dh_cornerRadius = 13
        }
        if let arrowImg = rightArrow {
            arrowImg.image = UIImage(named: "common_listicon_s_next")
        }
        if let line = lineView {
            line.backgroundColor = UIColor.dhcolor_c8()
        }
        if let dotImg = dotImgV {
            dotImg.image = UIImage.init(named: "device_icon_onlinepoint")
        }
        contentView.backgroundColor = UIColor.dhcolor_c10()
        backgroundColor = UIColor.dhcolor_c10()
    }
 
    override public func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
 
        // Configure the view for the selected state
    }
 
    public func config(detailItem: IDHDeviceDetailItem) {
        titleLbl.text = detailItem.itemName
        rightLbl.text = detailItem.contentStr
        
        redDot.isHidden = !detailItem.showRedDot
      
        self.loadingView.isHidden = detailItem.state != .loading  //加载过程中 展示菊花
        rightLbl.isHidden = !self.loadingView.isHidden
        self.rightLbl.textColor = detailItem.isContentDiable ? UIColor.dhcolor_c6() : UIColor.dhcolor_c5()
        self.loadingView.startAnimating()
        
        if detailItem.desString.count != 0 {
            let style: NSMutableParagraphStyle = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
            // 头部缩进
            style.headIndent = 15
            style.firstLineHeadIndent = 15
            // 尾部缩进
            style.tailIndent = -15
            
            let str = NSMutableAttributedString(string: "\n", attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 6)])
            
            str.append(NSMutableAttributedString(string: detailItem.desString, attributes: [NSAttributedStringKey.paragraphStyle: style, NSAttributedStringKey.font: UIFont.dhFont_t6()]))
            
            str.append(NSMutableAttributedString(string: "\n", attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 2), NSAttributedStringKey.foregroundColor: UIColor.dhcolor_c5()]))
                descriptLbl.attributedText = str
            self.separatorInset = UIEdgeInsetsMake(0, UIScreen.main.bounds.size.width, 0, 0); //
        } else {
            descriptLbl.text = ""
            descriptLbl.attributedText = NSMutableAttributedString()
            self.separatorInset = UIEdgeInsetsMake(0, 15, 0, 0)
        }
 
        self.setArrowHidden(isHidden: !detailItem.isShowArrow)
        self.isUserInteractionEnabled = detailItem.isEnable
        
        if detailItem.cellType == .check {
            self.rightArrow.image = UIImage(named: "setting_icon_check")
        } else {
            self.rightArrow.image = UIImage(named: "common_listicon_s_next")
        }
    }
    
    func setArrowHidden(isHidden: Bool) {
        if isHidden {
            self.rightArrow.snp.updateConstraints { (make) in
                make.width.equalTo(0)
            }
            self.layoutIfNeeded()
        } else {
            self.rightArrow.snp.updateConstraints { (make) in
                make.width.equalTo(20)
            }
        }
        self.layoutIfNeeded()
    }
}