SearchBarView.swift 2.34 KB
//
//  SearchBarView.swift
//  browser
//
//  Created by Artem Talko on 26.09.2023.
//

import UIKit

final class SearchBarView: UIView {
    let searchImageView: UIImageView = {
        let obj = UIImageView()
        let magnifyImage = UIImage(systemName: "magnifyingglass")?.withTintColor(.gray, renderingMode: .alwaysOriginal)
        obj.image = magnifyImage
        return obj
    }()
    
    let searchTextFieldView: UITextField = {
        let obj = UITextField()
        obj.text = "Search"
        obj.textColor =  ColorConstants.gray
        return obj
    }()
    
    let cleanTextFieldButton: UIButton = {
        let obj = UIButton()
        obj.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal)
        obj.tintColor = .black
        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()
        setupConstraints()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setup() {
        addSubview(progressBar)
        addSubview(searchImageView)
        addSubview(searchTextFieldView)
        addSubview(cleanTextFieldButton)
    }
    
    private func setupConstraints() {
        searchImageView.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(16.sizeW)
            make.top.bottom.equalToSuperview().inset(8.sizeH)
        }
        searchTextFieldView.snp.makeConstraints { make in
            make.leading.equalTo(searchImageView).offset(32.sizeW)
            make.trailing.equalToSuperview().offset(-16.sizeW)
            make.top.bottom.equalToSuperview().inset(8.sizeH)
        }
        cleanTextFieldButton.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-16.sizeW)
            make.top.bottom.equalToSuperview().inset(8.sizeH)
        }
        progressBar.snp.makeConstraints { make in
            make.bottom.equalToSuperview().inset(2.sizeH)
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(2)
        }
    }
}