import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
// Create and configure buttons for each store
let stores = [
("Every Mailbox Shop", "https://everymailbox.shop"),
("My Amazon Store", "https://www.amazon.com"),
("My eBay", "https://www.ebay.com"),
("Jody's eBay", "https://www.ebay.com"),
("My Podcast", "https://mypodcastlink.com"),
("YouTube", "https://www.youtube.com")
]
var yOffset = 100
for store in stores {
let button = UIButton(type: .system)
button.setTitle(store.0, for: .normal)
button.frame = CGRect(x: 20, y: yOffset, width: 300, height: 50)
button.backgroundColor = .blue
button.setTitleColor(.white, for: .normal)
button.layer.cornerRadius = 10
button.addTarget(self, action: #selector(openStore(_:)), for: .touchUpInside)
button.tag = yOffset // Unique identifier for each button
button.accessibilityLabel = store.1 // Store URL
view.addSubview(button)
yOffset += 60
}
}
@objc func openStore(_ sender: UIButton) {
if let urlString = sender.accessibilityLabel, let url = URL(string: urlString) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}