//
//  CornerLabelView.swift
//  MachineLearningDemo
//
//  Created by Pavel Odstrčilík on 28.04.2021.
//

import Foundation
import UIKit

open class CornerLabelView: UIView {

    init(frame: CGRect, text: String?) {
        super.init(frame: frame)
        prepareCornerView()
        if let textUnwrapped = text {
            prepareLabel(text: textUnwrapped)
        }
    }

    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    open func prepareCornerView() {
        self.backgroundColor = .clear
        self.layer.borderWidth = 2
        self.layer.borderColor = UIColor.white.cgColor
        self.layer.cornerRadius = 10
    }

    open func prepareLabel(text: String) {
        let label = UILabel()
        label.text = text
        label.font = .systemFont(ofSize: 20, weight: .regular)
        label.textColor = UIColor.white.withAlphaComponent(0.8)
        self.addSubview(label)
        label.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
        }
    }
}
