| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- //
- // BaseTransactionCell.swift
- // MTP2_iOS
- //
- // Created by zhongyuan on 2018/4/4.
- // Copyright © 2018年 zhongyuan.All rights reserved.
- //
- import UIKit
- import MGSwipeTableCell
- class BaseTableViewCell<Model>: MGSwipeTableCell {
- /// 模型数据
- var model: Model?
- /// cell所在的行
- var rowNum: Int?
- /// 携带信息
- var takeInfo: Any?
- /// 是否拓展
- var isExpland: Bool = false {
- didSet {
- /// 背景色
- self.contentView.backgroundColor = isExpland ? .F0F5F9() : .white
- }
- }
- /// 回调
- var block: ((_ model: Model?, _ sender: Any?) -> Void)?
- /// 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
- }
- }
- }
- // 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
- }
- }
|