|
@@ -3,15 +3,35 @@ import DcCore
|
|
|
|
|
|
class ChatTitleView: UIView {
|
|
|
|
|
|
- private var titleLabel: UILabel = {
|
|
|
+ private lazy var titleLabel: UILabel = {
|
|
|
let titleLabel = UILabel()
|
|
|
titleLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
titleLabel.backgroundColor = UIColor.clear
|
|
|
titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .semibold)
|
|
|
titleLabel.textAlignment = .center
|
|
|
+ titleLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
|
|
|
return titleLabel
|
|
|
}()
|
|
|
|
|
|
+ private lazy var verifiedView: UIImageView = {
|
|
|
+ let imgView = UIImageView()
|
|
|
+ let img = UIImage(named: "verified")?.scaleDownImage(toMax: 18)
|
|
|
+ imgView.isHidden = true
|
|
|
+ imgView.image = img
|
|
|
+ imgView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ imgView.setContentCompressionResistancePriority(.required, for: .horizontal)
|
|
|
+ return imgView
|
|
|
+ }()
|
|
|
+
|
|
|
+ private lazy var titleContainer: UIStackView = {
|
|
|
+ let stackView = UIStackView(arrangedSubviews: [titleLabel, verifiedView])
|
|
|
+ stackView.axis = .horizontal
|
|
|
+ stackView.alignment = .firstBaseline
|
|
|
+ stackView.spacing = 3
|
|
|
+ stackView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ return stackView
|
|
|
+ }()
|
|
|
+
|
|
|
private var subtitleLabel: UILabel = {
|
|
|
let subtitleLabel = UILabel()
|
|
|
subtitleLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
@@ -37,30 +57,30 @@ class ChatTitleView: UIView {
|
|
|
let containerView = UIView()
|
|
|
containerView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
addSubview(containerView)
|
|
|
+ containerView.addSubview(titleContainer)
|
|
|
+ containerView.addSubview(subtitleLabel)
|
|
|
|
|
|
addConstraints([ containerView.constraintAlignTopTo(self),
|
|
|
containerView.constraintAlignBottomTo(self),
|
|
|
containerView.constraintCenterXTo(self),
|
|
|
containerView.constraintAlignLeadingTo(self),
|
|
|
- containerView.constraintAlignTrailingTo(self)
|
|
|
+ containerView.constraintAlignTrailingTo(self),
|
|
|
+ titleContainer.constraintAlignLeadingTo(containerView),
|
|
|
+ titleContainer.constraintAlignTrailingTo(containerView),
|
|
|
+ titleContainer.constraintAlignTopTo(containerView),
|
|
|
+ subtitleLabel.constraintToBottomOf(titleContainer),
|
|
|
+ subtitleLabel.constraintAlignLeadingTo(containerView),
|
|
|
+ subtitleLabel.constraintAlignTrailingTo(containerView),
|
|
|
+ subtitleLabel.constraintAlignBottomTo(containerView),
|
|
|
+ verifiedView.widthAnchor.constraint(equalTo: verifiedView.heightAnchor)
|
|
|
])
|
|
|
-
|
|
|
- containerView.addSubview(titleLabel)
|
|
|
- containerView.addConstraints([ titleLabel.constraintAlignLeadingTo(containerView),
|
|
|
- titleLabel.constraintAlignTrailingTo(containerView),
|
|
|
- titleLabel.constraintAlignTopTo(containerView) ])
|
|
|
-
|
|
|
- containerView.addSubview(subtitleLabel)
|
|
|
- containerView.addConstraints([ subtitleLabel.constraintToBottomOf(titleLabel),
|
|
|
- subtitleLabel.constraintAlignLeadingTo(containerView),
|
|
|
- subtitleLabel.constraintAlignTrailingTo(containerView),
|
|
|
- subtitleLabel.constraintAlignBottomTo(containerView)])
|
|
|
}
|
|
|
|
|
|
- func updateTitleView(title: String, subtitle: String?, baseColor: UIColor = DcColors.defaultTextColor) {
|
|
|
+ func updateTitleView(title: String, subtitle: String?, baseColor: UIColor = DcColors.defaultTextColor, isVerified: Bool) {
|
|
|
subtitleLabel.textColor = baseColor.withAlphaComponent(0.95)
|
|
|
titleLabel.textColor = baseColor
|
|
|
titleLabel.text = title
|
|
|
subtitleLabel.text = subtitle
|
|
|
+ verifiedView.isHidden = !isVerified
|
|
|
}
|
|
|
}
|