Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
677 B
0
Indexable
Never
import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Create a button
        let button = UIButton(type: .system)
        button.setTitle("Click me", for: .normal)
        button.frame = CGRect(x: 100, y: 100, width: 200, height: 40)
        
        // Add a target to the button
        button.addTarget(self, action: #selector(buttonClicked), for: .touchUpInside)
        
        // Add the button to the view
        view.addSubview(button)
    }
    
    // Function to handle button click
    @objc func buttonClicked() {
        print("Button clicked!")
    }
}
Leave a Comment