-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathBulletView.swift
78 lines (67 loc) · 1.87 KB
/
BulletView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// BulletView.swift
// LockdownSandbox
//
// Created by Алишер Ахметжанов on 27.04.2023.
//
import UIKit
struct BulletViewModel {
let image: UIImage
let title: String
let highlightedStrings: [String]
init(
image: UIImage,
title: String,
highlightedStrings: [String] = []
) {
self.image = image
self.title = title
self.highlightedStrings = highlightedStrings
}
}
final class BulletView: UIView {
private lazy var bulletImage: UIImageView = {
let image = UIImageView()
image.contentMode = .left
image.anchors.width.equal(24)
return image
}()
lazy var titleLabel: UILabel = {
let label = UILabel()
label.textColor = .white
label.font = fontMedium15
label.textAlignment = .left
label.numberOfLines = 0
return label
}()
lazy var stackView: UIStackView = {
let stackView = UIStackView()
stackView.addArrangedSubview(bulletImage)
stackView.addArrangedSubview(titleLabel)
stackView.axis = .horizontal
stackView.distribution = .fill
stackView.alignment = .top
stackView.spacing = 8
return stackView
}()
//MARK: Initialization
override init(frame: CGRect) {
super.init(frame: frame)
configureUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//MARK: Functions
private func configureUI() {
addSubview(stackView)
stackView.anchors.edges.pin()
}
func configure(with model: BulletViewModel) {
bulletImage.image = model.image
titleLabel.text = model.title
model.highlightedStrings.forEach {
titleLabel.highlight($0, font: .boldLockdownFont(size: 15))
}
}
}