Ios/swift/ボタン
提供: 初心者エンジニアの簡易メモ
ボタンを追加
class ViewController: UIViewController { var button1: UIButton! override func viewDidLoad() { super.viewDidLoad() button1 = UIButton() button1.frame = CGRectMake(100, 250, 150, 50) button1.setTitle("押す前", forState: .Normal) button1.backgroundColor = UIColor.yellowColor() button1.addTarget(self, action: #selector(ViewController.onClickMyButton(_:)), forControlEvents: .TouchUpInside) self.view.addSubview(button1) } internal func onClickMyButton(sender: UIButton) { button1.setTitle("押された", forState: .Normal) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }