51
51

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

swiftでIBOutlet, IBAction

Posted at

@IBOutlet@IBActionで宣言するとstoryboardからも認識されます。
以下はタップしたUIButtonのタイトルを変更するサンプルです。
objective-cで書くときと同じようにstoryboardから@IBOutlet@IBActionをつないであげて下さい。


import UIKit

class ViewController: UIViewController {
    
    @IBOutlet var button:UIButton
    @IBAction func buttonTapped(sender:AnyObject) {
        var tappedButton:UIButton = sender as UIButton
        tappedButton.setTitle("tapped", forState:UIControlState.Normal)
    }
                            
    override func viewDidLoad() {
        super.viewDidLoad()
        button.setTitle("tap me", forState:UIControlState.Normal)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

51
51
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
51
51

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?