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. } }
参考:http://swift-nyumon.info/button_action_with_swift 参考:https://sites.google.com/a/gclue.jp/swift-docs/ni-yinki100-ios/uikit/002-uibuttondebotanwo-biao-shi 参考(#selector):http://egg-is-world.com/2016/04/11/swift22-changes/