commit
709e89cbfb
@ -1,76 +1,78 @@ |
||||
// Copyright © 2020 Stormbird PTE. LTD. |
||||
|
||||
import UIKit |
||||
extension AddHideTokensViewController { |
||||
class functional {} |
||||
} |
||||
|
||||
extension AddHideTokensViewController.functional { |
||||
|
||||
static func headerView(for section: Int, viewModel: AddHideTokenSectionHeaderViewModel) -> UIView { |
||||
let view = AddHideTokenSectionHeaderView() |
||||
view.configure(viewModel: viewModel) |
||||
|
||||
return view |
||||
} |
||||
} |
||||
|
||||
private class AddHideTokenSectionHeaderView: UIView { |
||||
|
||||
class AddHideTokenSectionHeaderView: UITableViewHeaderFooterView { |
||||
private lazy var titleLabel: UILabel = { |
||||
private let titleLabel: UILabel = { |
||||
let label = UILabel() |
||||
label.translatesAutoresizingMaskIntoConstraints = false |
||||
label.font = Fonts.bold(size: 24) |
||||
label.textColor = .black |
||||
|
||||
return label |
||||
}() |
||||
|
||||
var rightAccessoryView: UIView? { |
||||
didSet { |
||||
if let view = rightAccessoryView { |
||||
setup(rightAccessoryView: view) |
||||
} else if let oldValue = oldValue { |
||||
oldValue.removeFromSuperview() |
||||
} |
||||
} |
||||
} |
||||
|
||||
private var separatorView: UIView = { |
||||
|
||||
private let topSeparator: UIView = { |
||||
let view = UIView() |
||||
view.translatesAutoresizingMaskIntoConstraints = false |
||||
|
||||
view.backgroundColor = R.color.mercury() |
||||
return view |
||||
}() |
||||
|
||||
override init(reuseIdentifier: String?) { |
||||
super.init(reuseIdentifier: reuseIdentifier) |
||||
setupViews() |
||||
} |
||||
|
||||
required init?(coder: NSCoder) { |
||||
fatalError("init(coder:) has not been implemented") |
||||
} |
||||
|
||||
override func awakeFromNib() { |
||||
super.awakeFromNib() |
||||
|
||||
setupViews() |
||||
} |
||||
|
||||
private func setupViews() { |
||||
backgroundColor = .white |
||||
contentView.backgroundColor = .white |
||||
addSubview(titleLabel) |
||||
addSubview(separatorView) |
||||
|
||||
|
||||
private let bottomSperator: UIView = { |
||||
let view = UIView() |
||||
view.translatesAutoresizingMaskIntoConstraints = false |
||||
view.backgroundColor = R.color.mercury() |
||||
return view |
||||
}() |
||||
|
||||
private var topSeparatorHeight: NSLayoutConstraint! |
||||
|
||||
init() { |
||||
super.init(frame: .zero) |
||||
|
||||
let stackView = [ |
||||
topSeparator, |
||||
.spacer(height: 20, backgroundColor: .clear), |
||||
[.spacerWidth(16), titleLabel, .spacerWidth(16)].asStackView(axis: .horizontal), |
||||
.spacer(height: 20, backgroundColor: .clear), |
||||
bottomSperator |
||||
].asStackView(axis: .vertical) |
||||
stackView.translatesAutoresizingMaskIntoConstraints = false |
||||
addSubview(stackView) |
||||
|
||||
NSLayoutConstraint.activate([ |
||||
titleLabel.centerYAnchor.constraint(equalTo: centerYAnchor), |
||||
titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16), |
||||
separatorView.centerXAnchor.constraint(equalTo: centerXAnchor), |
||||
separatorView.widthAnchor.constraint(equalTo: widthAnchor), |
||||
separatorView.heightAnchor.constraint(equalToConstant: GroupedTable.Metric.cellSeparatorHeight), |
||||
separatorView.bottomAnchor.constraint(equalTo: bottomAnchor) |
||||
stackView.anchorsConstraint(to: self), |
||||
bottomSperator.heightAnchor.constraint(equalToConstant: 1) |
||||
]) |
||||
|
||||
topSeparatorHeight = topSeparator.heightAnchor.constraint(equalToConstant: 1) |
||||
topSeparatorHeight.isActive = true |
||||
} |
||||
|
||||
private func setup(rightAccessoryView: UIView) { |
||||
addSubview(rightAccessoryView) |
||||
|
||||
NSLayoutConstraint.activate([ |
||||
rightAccessoryView.widthAnchor.constraint(equalTo: widthAnchor), |
||||
rightAccessoryView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16) |
||||
]) |
||||
|
||||
required init?(coder aDecoder: NSCoder) { |
||||
fatalError("init(coder:) has not been implemented") |
||||
} |
||||
|
||||
|
||||
func configure(viewModel: AddHideTokenSectionHeaderViewModel) { |
||||
titleLabel.text = viewModel.text |
||||
separatorView.backgroundColor = viewModel.separatorColor |
||||
titleLabel.text = viewModel.titleText |
||||
titleLabel.textColor = viewModel.titleTextColor |
||||
titleLabel.font = viewModel.titleTextFont |
||||
|
||||
topSeparator.backgroundColor = viewModel.separatorColor |
||||
bottomSperator.backgroundColor = viewModel.separatorColor |
||||
backgroundColor = viewModel.backgroundColor |
||||
topSeparatorHeight.constant = viewModel.showTopSeparator ? 1 : 0 |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue