You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.7 KiB
117 lines
3.7 KiB
// |
|
// CommonTableViewCell.swift |
|
// Lookfit |
|
// |
|
// Created by lemo. on 2020/3/22. |
|
// Copyright © 2020 Sheldon. All rights reserved. |
|
// |
|
|
|
import UIKit |
|
|
|
struct TableViewCellModel { |
|
/// UI相关 |
|
var title: String = "" |
|
var isSwitch: Bool = false |
|
var description: String? |
|
var isArrows: Bool = false |
|
var isOn: Bool = false |
|
var image: UIImage? |
|
var isBottomLine: Bool = true |
|
var righeImg: UIImage? |
|
let redPoint = BehaviorRelay<Bool>(value: false) |
|
var rightBottomText: String? |
|
/// 我的类型 |
|
var mineSetType: MineSetType? |
|
/// 用户信息类型 |
|
var userInfoType: UserInfoType? |
|
/// 设备设置功能类型 |
|
var functionType: FunctionType? |
|
/// 推送功能类型 |
|
var pushType: PushType? |
|
/// 目标类型 |
|
var targetType: UserTargetType? |
|
} |
|
|
|
class CommonTableViewCell: TableViewCell { |
|
|
|
@IBOutlet weak var titleLabel: UILabel! |
|
@IBOutlet weak var img: UIImageView! |
|
@IBOutlet weak var imageTitleLabel: UILabel! |
|
@IBOutlet weak var rightSwitch: UISwitch! |
|
@IBOutlet weak var detailLabel: UILabel! |
|
@IBOutlet weak var bottomLineView: UIView! |
|
@IBOutlet weak var rightImg: UIImageView! |
|
@IBOutlet weak var rightConstraintsW: NSLayoutConstraint! |
|
@IBOutlet weak var rightConstraintsH: NSLayoutConstraint! |
|
@IBOutlet weak var redPoint: UIImageView! |
|
|
|
lazy var rightBottomLabel: UILabel = { |
|
let view = UILabel() |
|
view.textColor = .green |
|
view.font = UIFont.systemFont(ofSize: 16) |
|
return view |
|
}() |
|
|
|
override func awakeFromNib() { |
|
super.awakeFromNib() |
|
addSubview(rightBottomLabel) |
|
rightBottomLabel.snp.makeConstraints { make in |
|
make.top.equalTo(detailLabel.snp.bottom).offset(5) |
|
make.right.equalTo(detailLabel.snp.right) |
|
} |
|
} |
|
|
|
func bindViewModel(model: TableViewCellModel) { |
|
titleLabel.text = model.title |
|
imageTitleLabel.text = model.title |
|
if let image = model.image { |
|
img.image = image |
|
img.isHidden = false |
|
imageTitleLabel.isHidden = false |
|
titleLabel.isHidden = true |
|
}else { |
|
img.isHidden = true |
|
imageTitleLabel.isHidden = true |
|
titleLabel.isHidden = false |
|
} |
|
rightSwitch.isHidden = !model.isSwitch |
|
rightSwitch.isOn = model.isOn |
|
accessoryType = model.isArrows ? .disclosureIndicator : .none |
|
bottomLineView.isHidden = !model.isBottomLine |
|
// 主题修改 |
|
if let userInfoType = model.userInfoType { |
|
titleLabel.textColor = kHexColor(0x969696) |
|
detailLabel.textColor = kHexColor(0x2A2A2A) |
|
detailLabel.font = SystemRegularFont(18) |
|
rightImg.layer.cornerRadius = kScaleWidth(45) / 2 |
|
rightImg.layer.masksToBounds = true |
|
if userInfoType == .head { |
|
rightConstraintsW.constant = kScaleWidth(45) |
|
rightConstraintsH.constant = kScaleWidth(45) |
|
} |
|
} |
|
if let description = model.description { |
|
detailLabel.text = description |
|
detailLabel.isHidden = false |
|
}else { |
|
detailLabel.isHidden = true |
|
} |
|
if let image = model.righeImg { |
|
rightImg.image = image |
|
rightImg.isHidden = false |
|
}else { |
|
rightImg.isHidden = true |
|
} |
|
model.redPoint.asDriver() |
|
.map { !$0 } |
|
.drive(redPoint.rx.isHidden) |
|
.disposed(by: cellDisposeBag) |
|
if let rightBottomText = model.rightBottomText { |
|
rightBottomLabel.text = rightBottomText |
|
rightBottomLabel.isHidden = false |
|
}else { |
|
rightBottomLabel.isHidden = true |
|
} |
|
} |
|
|
|
}
|
|
|