Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created July 21, 2020 05:28
Show Gist options
  • Save SunXiaoShan/1155bad3bf62707a1bbb75d71bb1f6cf to your computer and use it in GitHub Desktop.
Save SunXiaoShan/1155bad3bf62707a1bbb75d71bb1f6cf to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController {
var label:UILabel? = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
setupHardCodeLabel()
setupHardCodeButton()
}
func setupHardCodeLabel() {
let rect = CGRect(x: 100, y: 200, width: 300, height: 45)
let label = UILabel(frame: rect)
label.text = "Hello World!!!!!!!"
self.label = label
self.view.addSubview(label)
}
func setupHardCodeButton() {
let rect = CGRect(x: 100, y: 300, width: 300, height: 45)
let button = UIButton(frame: rect)
button.setTitle("Click", for: .normal)
button.setTitleColor(.blue, for: .normal)
button.addTarget(self, action: #selector(actionButtonClick), for: .touchUpInside)
self.view.addSubview(button)
}
@objc func actionButtonClick(button:UIButton) {
self.label?.text = "Action the button event!!"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment