CodeVerificationView.swift 7.29 KB
//
//  CodeVerificationView.swift
//  InterQR-Internship
//
//  Created by Дмитрий Тимофеев on 03.06.2022.
//

import UIKit

class CodeVerificationView: UIView {
    var containerView: UIView = {
        var obj = UIView()
        return obj
    }()
    
    var backButton: UIButton = {
        var obj = UIButton()
        obj.setImage(UIImage(named: "BackPointer"), for: .normal)
        obj.backgroundColor = .white
        obj.layer.borderColor = UIColor(red: 224/255, green: 231/255, blue: 232/255, alpha: 1).cgColor
        obj.layer.cornerRadius = 13
        obj.layer.borderWidth = 1
        return obj
    }()
    
    var logoImage: UIImageView = {
        var obj = UIImageView()
        obj.image = UIImage(named: "InterQR")
        return obj
    }()
    
    var shieldImage: UIImageView = {
        var obj = UIImageView()
        obj.image = UIImage(named: "Lock")
        return obj
    }()
    
    var descriptionLabel: UILabel = {
        var obj = UILabel()
        obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 35)
        obj.text = "Enter your\nverification code"
        obj.numberOfLines = 2
        return obj
    }()
    
    var textField: UITextField = {
        let obj = UITextField()
        obj.returnKeyType = .done
        obj.keyboardType = .numberPad
        obj.becomeFirstResponder()
        obj.isHidden = true
        return obj
    }()
    
    var firstDigitLabel: UILabel = {
        let obj = UILabel()
        obj.font = .skModernist(type: .bold, ofSize: 16)
        obj.textColor = .black
        obj.textAlignment = .center
        obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1)
        obj.layer.cornerRadius = 15
        obj.clipsToBounds = true
        return obj
    }()
    
    var secondDigitLabel: UILabel = {
        let obj = UILabel()
        obj.font = .skModernist(type: .bold, ofSize: 16)
        obj.textColor = .black
        obj.textAlignment = .center
        obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1)
        obj.layer.cornerRadius = 15
        obj.clipsToBounds = true
        return obj
    }()
    
    var thirdDigitLabel: UILabel = {
        let obj = UILabel()
        obj.font = .skModernist(type: .bold, ofSize: 16)
        obj.textColor = .black
        obj.textAlignment = .center
        obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1)
        obj.layer.cornerRadius = 15
        obj.clipsToBounds = true
        return obj
    }()
    
    var fourthDigitLabel: UILabel = {
        let obj = UILabel()
        obj.font = .skModernist(type: .bold, ofSize: 16)
        obj.textColor = .black
        obj.textAlignment = .center
        obj.backgroundColor = UIColor(red: 0.954, green: 0.954, blue: 0.954, alpha: 1)
        obj.layer.cornerRadius = 15
        obj.clipsToBounds = true
        return obj
    }()
    
    var errorAlertLabel: UILabel = {
        var obj = UILabel()
        obj.text = "Please, enter valid verification code"
        obj.font = UIFont(name: SkModernistFontType.regular.rawValue, size: 14)
        obj.textColor = UIColor(red: 255/255, green: 0/255, blue: 46/255, alpha: 1)
        obj.isHidden = true
        return obj
    }()
    
    var verifyButton: UIButton = {
        var obj = UIButton()
        obj.setImage(UIImage(named: "RectangleWithShadow"), for: .normal)
        return obj
    }()
    
    var verifyLabel: UILabel = {
        var obj = UILabel()
        obj.font = UIFont(name: SkModernistFontType.bold.rawValue, size: 16)
        obj.textColor = .white
        obj.text = "Verify"
        return obj
    }()
    
    var tickImage: UIImageView = {
        var obj = UIImageView()
        obj.image = UIImage(named: "Tick")
        return obj
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        layout()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func layout() {
        backgroundColor = .white
        
        addSubview(textField)
        addSubview(backButton)
        addSubview(logoImage)
        addSubview(shieldImage)
        
        addSubview(containerView)
        containerView.addSubview(descriptionLabel)
        containerView.addSubview(firstDigitLabel)
        containerView.addSubview(secondDigitLabel)
        containerView.addSubview(thirdDigitLabel)
        containerView.addSubview(fourthDigitLabel)
        containerView.addSubview(errorAlertLabel)
        
        containerView.addSubview(verifyButton)
        verifyButton.addSubview(verifyLabel)
        verifyButton.addSubview(tickImage)
        
        backButton.snp.makeConstraints {
            $0.top.equalTo(snp.top).offset(66)
            $0.leading.equalTo(snp.leading).offset(22)
            $0.height.width.equalTo(45)
        }
        
        logoImage.snp.makeConstraints {
            $0.leading.equalTo(backButton.snp.trailing).offset(20)
            $0.centerY.equalTo(backButton)
        }
        
        shieldImage.snp.makeConstraints {
            $0.top.equalTo(backButton.snp.bottom).offset(25)
            $0.right.equalTo(snp.right).offset(-101)
        }
        
        containerView.snp.makeConstraints {
            $0.top.equalTo(backButton.snp.bottom).offset(227)
            $0.leading.trailing.equalToSuperview()
            $0.height.equalTo(300)
        }
        
        descriptionLabel.snp.makeConstraints {
            $0.leading.equalTo(containerView.snp.leading).offset(20)
            $0.top.equalTo(containerView.snp.top)
        }
        
        firstDigitLabel.snp.makeConstraints {
            $0.leading.equalTo(containerView.snp.leading).offset(25)
            $0.top.equalTo(descriptionLabel.snp.bottom).offset(28)
            $0.height.equalTo(55)
        }
        
        secondDigitLabel.snp.makeConstraints {
            $0.leading.equalTo(firstDigitLabel.snp.trailing).offset(12)
            $0.centerY.equalTo(firstDigitLabel)
            $0.width.equalTo(firstDigitLabel.snp.width)
            $0.height.equalTo(55)
        }
        
        thirdDigitLabel.snp.makeConstraints {
            $0.leading.equalTo(secondDigitLabel.snp.trailing).offset(12)
            $0.centerY.equalTo(firstDigitLabel)
            $0.width.equalTo(firstDigitLabel.snp.width)
            $0.height.equalTo(55)
        }
        
        fourthDigitLabel.snp.makeConstraints {
            $0.leading.equalTo(thirdDigitLabel.snp.trailing).offset(12)
            $0.centerY.equalTo(firstDigitLabel)
            $0.trailing.equalTo(containerView.snp.trailing).offset(-25)
            $0.width.equalTo(firstDigitLabel.snp.width)
            $0.height.equalTo(55)
        }
        
        errorAlertLabel.snp.makeConstraints {
            $0.top.equalTo(firstDigitLabel.snp.bottom).offset(8)
            $0.leading.equalTo(firstDigitLabel.snp.leading)
        }
        
        verifyButton.snp.makeConstraints {
            $0.top.equalTo(firstDigitLabel.snp.bottom).offset(67)
            $0.left.right.equalToSuperview()
        }
        
        verifyLabel.snp.makeConstraints {
            $0.left.equalToSuperview().offset(49)
            $0.top.equalToSuperview().offset(22)
        }
        
        tickImage.snp.makeConstraints {
            $0.right.equalToSuperview().offset(-47)
            $0.centerY.equalTo(verifyLabel)
        }
    }
}