Created
July 21, 2020 05:28
-
-
Save SunXiaoShan/1155bad3bf62707a1bbb75d71bb1f6cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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