UIButtonの文字の変更

UIButtonの文字の変更 iOS

UIButtonの文字を動的に変更したい場合はIBActionに記述します。

以下のように設定することで、ボタンがタップされた時に文字が変更します。

@IBAction func greeting(_ sender: UIButton) {
    sender.titleLabel?.text = "こんにちは!"
}

参考記事