PopupInfoViewController.swift 3.88 KB
//
//  PopupInfoViewController.swift
//  SwiftWarplyFramework
//
//  Created by Manos Chorianopoulos on 16/10/24.
//

import UIKit

class PopupInfoViewController: UIViewController {
    @IBOutlet weak var containerView: UIView!
    @IBOutlet weak var popupView: UIView!
    @IBOutlet weak var headerLabel: UILabel!
    @IBOutlet weak var headerCloseButton: UIButton!
    @IBOutlet weak var infoLabel: UILabel!
    @IBOutlet weak var submitButton: UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Add arrow programmatically
        let arrowSize = CGSize(width: 15, height: 7.5)  // Width and height of the arrow
        let arrowView = ArrowView(frame: CGRect(
            x: (popupView.frame.width - arrowSize.width - 35),
            y: popupView.frame.minY - arrowSize.height,
            width: arrowSize.width,
            height: arrowSize.height))

        containerView.addSubview(arrowView)
//        containerView.bringSubviewToFront(popupView)
        
        // Add shadow
        containerView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.57).cgColor
        containerView.layer.shadowOffset = CGSize(width: 0.0, height: 3.0)
        containerView.layer.shadowOpacity = 1.0
        containerView.layer.shadowRadius = 20.0
        containerView.layer.masksToBounds = false
        containerView.backgroundColor = .clear
        
        popupView.backgroundColor = UIColor(rgb: 0xE6E6E6)
        popupView.layer.cornerRadius = 14
        
        headerLabel.font = UIFont(name: "BTCosmo-Bold", size: 17)
        headerLabel.textColor = UIColor(rgb: 0x212121)
        headerLabel.text = "SUPERMARKET DEALS"
        
        headerCloseButton.setImage(UIImage(named: "ic_close_3.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
        headerCloseButton.imageView?.layer.transform = CATransform3DMakeScale(1.3, 1.3, 1.3)
        
        infoLabel.font = UIFont(name: "PeridotPE-Regular", size: 16.0)
        infoLabel.textColor = UIColor(rgb: 0x212121)
        infoLabel.text = "Δημιούργησε το δικό σου ενιαίο κουπόνι προσφορών, και εξαργύρωσέ το στα supermarket της επιλογής σου γρήγορα και εύκολα με ένα μόνο κωδικό κουπονιού!"
        
        submitButton.titleLabel?.font = UIFont(name: "PeridotPE-Bold", size: 14)
        submitButton.setTitle("Τέλος", for: .normal)
        submitButton.setTitleColor(UIColor(rgb: 0x212121), for: .normal)
        submitButton.frame.size.width = submitButton.intrinsicContentSize.width
    }
    
    // MARK: - Actions
    @IBAction func headerCloseButtonAction(_ sender: Any) {
        self.dismiss(animated: true, completion: {})
    }
    
    @IBAction func submitButtonAction(_ sender: Any) {
        self.dismiss(animated: true, completion: {})
    }
}

class ArrowView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .clear
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        self.backgroundColor = .clear
    }

    override func draw(_ rect: CGRect) {
        // Set up the context
        guard let context = UIGraphicsGetCurrentContext() else { return }

        // Set the arrow color (can adjust as needed)
        context.setFillColor(UIColor(rgb: 0xE6E6E6).cgColor)

        // Create the arrow's path (a triangle)
        let path = UIBezierPath()
        path.move(to: CGPoint(x: rect.width / 2, y: 0))           // Arrow top
        path.addLine(to: CGPoint(x: rect.width, y: rect.height))   // Bottom right
        path.addLine(to: CGPoint(x: 0, y: rect.height))            // Bottom left
        path.close()                                               // Close the triangle

        // Fill the arrow shape
        context.addPath(path.cgPath)
        context.fillPath()
    }
}