PageView.swift 2.56 KB
//
//  PageView.swift
//  Pro-Seecurity-VPN
//
//  Created by Volodymyr Kolomyltsev on 12/22/23.
//

import Foundation
import UIKit
import SnapKit

class PageView: UIView {
    
    var model: OnboardingType? {
        didSet {
            handleUI(model: model!)
        }
    }
    
    private let containerView: UIView = {
        let obj = UIView()
        
        
        return obj
    }()
    
    private let imgView: UIImageView = {
        let obj = UIImageView()
        obj.contentMode = .scaleAspectFill
        return obj
    }()
    
    private let titleLbl: UILabel = {
        let obj = UILabel()
        obj.lineBreakMode = .byWordWrapping
        obj.font = .systemFont(ofSize: 26, weight: .bold)
        obj.numberOfLines = 2
        obj.textAlignment = .center
        return obj
    }()
    
    private let subTitleLbl: UILabel = {
        let obj = UILabel()
        obj.font = .systemFont(ofSize: 15, weight: .regular)
        obj.lineBreakMode = .byWordWrapping
        obj.numberOfLines = 3
        obj.textAlignment = .center
        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 = .clear
        addSubview(containerView)
        containerView.addSubview(imgView)
        addSubview(titleLbl)
        addSubview(subTitleLbl)
        
        containerView.snp.makeConstraints { make in
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(220.sizeH)
            make.top.equalToSuperview()
            make.bottom.equalTo(titleLbl.snp.top).offset(-48.sizeH)
        }
        
        imgView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        titleLbl.snp.makeConstraints { make in
            make.bottom.equalTo(subTitleLbl.snp.top).offset(-8.sizeH)
            make.centerX.equalTo(containerView)
            make.width.equalTo(300.sizeW)
        }
        
        subTitleLbl.snp.makeConstraints { make in
//            make.top.equalTo(titleLbl.snp.bottom).offset(8.sizeH)
            make.width.equalTo(300.sizeW)
            make.centerX.equalTo(titleLbl)
            make.bottom.equalToSuperview()
        }
    }
    
}

//MARK: Helpers
extension PageView {
    
    private func handleUI(model: OnboardingType) {
        imgView.image = UIImage(named: model.imgString)
        titleLbl.text = model.title
        subTitleLbl.text = model.subTitle
    }
    
}