SearchBarView.swift
2.53 KB
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
79
80
81
82
83
84
85
86
87
88
//
// SearchBarView.swift
// browser
//
// Created by Artem Talko on 26.09.2023.
//
import UIKit
final class SearchBarView: UIView {
private let searchImageView: UIImageView = {
let obj = UIImageView()
let magnifyImage = UIImage(systemName: "magnifyingglass")?.withTintColor(ColorConstants.SearchbarTintBlue, renderingMode: .alwaysOriginal)
obj.image = magnifyImage
return obj
}()
let searchTextFieldView: UITextField = {
let obj = UITextField()
obj.text = "Search"
obj.textColor = ColorConstants.SearchbarTintBlue
obj.autocapitalizationType = .none
return obj
}()
let cleanTextFieldButton: UIButton = {
let obj = UIButton()
obj.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal)
obj.tintColor = ColorConstants.SearchbarTintBlue
obj.isHidden = true
return obj
}()
let progressBar: UIProgressView = {
let obj = UIProgressView(progressViewStyle: .default)
obj.progressTintColor = .systemIndigo
obj.progress = 0
obj.translatesAutoresizingMaskIntoConstraints = false
return obj
}()
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setup() {
addSubview(progressBar)
addSubview(searchImageView)
addSubview(searchTextFieldView)
addSubview(cleanTextFieldButton)
setupConstraints()
}
private func setupConstraints() {
searchImageView.snp.makeConstraints { make in
make.top.bottom.equalToSuperview().inset(8.sizeH)
make.leading.equalToSuperview().offset(16.sizeW)
}
searchTextFieldView.snp.makeConstraints { make in
make.top.bottom.equalToSuperview().inset(8.sizeH)
make.leading.equalTo(searchImageView).offset(32.sizeW)
make.trailing.equalToSuperview().offset(-16.sizeW)
}
cleanTextFieldButton.snp.makeConstraints { make in
make.top.bottom.equalToSuperview().inset(8.sizeH)
make.trailing.equalToSuperview().offset(-16.sizeW)
}
progressBar.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
make.bottom.equalToSuperview().inset(2.sizeH)
make.height.equalTo(2)
}
}
}