Manos Chorianopoulos

copy coupon code functionality

......@@ -121,12 +121,14 @@ import UIKit
mapButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16)
mapButton.setTitle("Καταστήματα κοντά μου", for: .normal)
mapButton.setTitleColor(UIColor(rgb: 0xFFFFFF), for: .normal)
mapButton.setTitleColor(UIColor(rgb: 0xFFFFFF), for: .highlighted)
mapButton.layer.cornerRadius = 4.0
mapButton.backgroundColor = UIColor(rgb: 0x000F1E)
websiteButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16)
websiteButton.setTitle("Δες το website", for: .normal)
websiteButton.setTitleColor(UIColor(rgb: 0x000F1E), for: .normal)
websiteButton.setTitleColor(UIColor(rgb: 0x000F1E), for: .highlighted)
websiteButton.backgroundColor = .clear
websiteButton.layer.borderWidth = 1
websiteButton.layer.borderColor = UIColor(rgb: 0x000F1E).cgColor
......@@ -164,6 +166,7 @@ import UIKit
couponCodeValueLabel.font = UIFont(name: "PingLCG-Bold", size: 24)
couponCodeValueLabel.textColor = UIColor(rgb: 0x000F1E)
couponCodeValueLabel.text = "coupons_ab"
copyButton.addTarget(self, action: #selector(copyButtonTapped), for: .touchUpInside)
couponQRTitleLabel.font = UIFont(name: "PingLCG-Regular", size: 16)
couponQRTitleLabel.textColor = UIColor(rgb: 0x000F1E)
......@@ -363,4 +366,73 @@ import UIKit
self.view.layoutIfNeeded()
}
}
@objc private func copyButtonTapped() {
// Get the coupon code text
guard let couponCode = couponCodeValueLabel.text else { return }
// Copy to clipboard
UIPasteboard.general.string = couponCode
// Show visual feedback
showCopyFeedback()
// Optional: Haptic feedback
let impactFeedback = UIImpactFeedbackGenerator(style: .medium)
impactFeedback.impactOccurred()
}
private func showCopyFeedback() {
// Store original image
// let originalImage = copyButtonImage.image
// Change to checkmark temporarily
// copyButtonImage.image = UIImage(systemName: "checkmark")
// copyButtonImage.tintColor = UIColor(rgb: 0x09914E) // Green color
// Show toast message
showToast(message: "Κωδικός αντιγράφηκε!")
// Reset after 1.5 seconds
// DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
// self.copyButtonImage.image = originalImage
// self.copyButtonImage.tintColor = UIColor(rgb: 0xCBCED1) // Original color
// }
}
private func showToast(message: String) {
// Create toast label
let toast = UILabel()
toast.backgroundColor = UIColor.black.withAlphaComponent(0.8)
toast.textColor = .white
toast.textAlignment = .center
toast.font = UIFont(name: "PingLCG-Regular", size: 14)
toast.text = message
toast.alpha = 0.0
toast.layer.cornerRadius = 8
toast.clipsToBounds = true
// Add to view
view.addSubview(toast)
toast.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
toast.centerXAnchor.constraint(equalTo: view.centerXAnchor),
toast.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -100),
toast.widthAnchor.constraint(equalToConstant: 200),
toast.heightAnchor.constraint(equalToConstant: 40)
])
// Animate in
UIView.animate(withDuration: 0.3, animations: {
toast.alpha = 1.0
}) { _ in
// Animate out after delay
UIView.animate(withDuration: 0.3, delay: 1.5, animations: {
toast.alpha = 0.0
}) { _ in
toast.removeFromSuperview()
}
}
}
}
......