TabCollectionViewCell.swift 1.95 KB
//
//  tabCell.swift
//  browser
//
//  Created by Artem Talko on 25.09.2023.
//
//MARK: Checked

import UIKit

final class TabCollectionViewCell: UICollectionViewCell {
    static let cellID = String(describing: TabCollectionViewCell.self)
    
    let tabCellImage: UIImageView = {
        let obj = UIImageView()
        obj.contentMode = .scaleToFill
        
        return obj
    }()
    
    let tabCellLabel: UILabel = {
        let obj = UILabel()
        obj.textColor = .black
        obj.font = FontConstants.regularFont_14
        
        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() {
        backgroundColor = .white
        layer.cornerRadius = 10
        contentView.backgroundColor = UIColor(red: 0.867, green: 0.867, blue: 0.863, alpha: 0.4)
        contentView.layer.cornerRadius = 10
        contentView.addSubview(tabCellImage)
        contentView.addSubview(tabCellLabel)
        
        setupConstraints()
    }
    
    private func setupConstraints() {
        tabCellImage.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(14.sizeH)
            make.leading.trailing.equalToSuperview().inset(9.sizeW)
            make.height.equalTo(50.sizeW)
        }
        
        tabCellLabel.snp.makeConstraints { make in
            make.top.equalTo(tabCellImage.snp.bottom).offset(8.sizeH)
            make.centerX.equalToSuperview()
        }
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        shadowSetup()
    }
}

//MARK: - Shadows
extension TabCollectionViewCell {
    private func shadowSetup() {
        layer.shadowColor = UIColor.gray.cgColor
        layer.shadowOpacity = 0.2
        layer.shadowRadius = 3
        layer.shadowOffset = CGSize(width: 2, height: 2)
    }
}