| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- //
- // BaseTransactionCell.swift
- // MTP2_iOS
- //
- // Created by zhongyuan on 2018/4/4.
- // Copyright © 2018年 zhongyuan.All rights reserved.
- //
- import UIKit
- class BaseTableViewCell<Model>: UITableViewCell {
- var model: Model? //模型数据
- /// 代理
- weak var delegate: BaseProtocal?
- /// cell所在的行
- var rowNum: Int?
- /// 携带信息
- var takeInfo: Any?
- /// MARK: -
- private var subviewsArray: [UIView: UIColor] {
-
- var array: [UIView: UIColor] = [:]
- for subview in hierarchySubViews {
-
- if NSStringFromClass(type(of: subview)).contains("UITableViewCellContentView") { continue }
-
- if let backgroundColor = subview.backgroundColor,
- backgroundColor != UIColor.clear,
- backgroundColor != UIColor.white {
-
- array[subview] = backgroundColor
- }
- }
- return array
- }
-
- /// 缓存
- private lazy var storageSubViews: [UIView: UIColor] = subviewsArray
- override func setHighlighted(_ highlighted: Bool, animated: Bool) {
- super.setHighlighted(highlighted, animated: animated)
- for (view, color) in storageSubViews {
- view.backgroundColor = color
- }
- }
- override func setSelected(_ selected: Bool, animated: Bool) {
- super.setSelected(selected, animated: animated)
- for (view, color) in storageSubViews {
- view.backgroundColor = color
- }
- }
-
- /// 选中相关
- /// - Parameter selected: selected
- func setCellSelected(_ selected: Bool) {
- self.contentView.backgroundColor = selected ? UIColorFromHex(rgbValue: 0x0A1E2F) : UIColorFromHex(rgbValue: 0x1e1e1e)
- }
- }
- // MARK: - 获取所有子view的方法
- extension UIView {
-
- var hierarchySubViews: [UIView] {
-
- var array = [UIView]()
-
- if let stackView = self as? UIStackView {
-
- for subview in stackView.arrangedSubviews {
-
- array.append(subview)
- array += subview.hierarchySubViews
- }
- } else {
-
- for subview in subviews {
-
- array.append(subview)
- array += subview.hierarchySubViews
- }
- }
- return array
- }
- }
- /// 基础协议,所有类代理必须继承该协议, 继承该协议是因为为了实现弱引用
- protocol BaseProtocal: class {
-
- }
|