2016-10-14 5 views
-2

下の図のような2つのボタンがあり、そのテキストラベルは「入力場所...」です。右のスワップボタンをクリックしたいので、これらのボタンのテキストラベルが入れ替わります。 2つの場所があり、それを交換したいと思うようです。誰にでも私にそれをする方法を教えてください。どうもありがとうございました。クリックでスウィフトの2つのボタンのラベルテキストを入れ替えます

screenShot

+2

'NSStringの* firstStr = [firstLabelテキスト]。 [firstLabel setText:[secondLabel text]]; [secondLabel setText:firstStr]; '? 「一般的な」サンプル:http://stackoverflow.com/questions/19255069/swap-any-type-of-two-variables-in-c – Larme

答えて

1

だけお互いに自分のテキストを設定します。

var tempString = secondButton.titleLabel.text 
secondButton.setTitle(firstButton.titleLabel.text, forState: UIControlState.Normal) 
firstButton.setTitle(tempString, forState: UIControlState.Normal) 
1
@IBOutlet var firstButton: UIButton! 
@IBOutlet var secondButton: UIButton! 

@IBAction func didTouchUpInsideSwapButton() { 

    let firstButtonText = firstButton.titleLabel?.text 

    firstButton.setTitle(secondButton.titleLabel?.text, for: .normal) 
    secondButton.setTitle(firstButtonText, for: .normal) 
} 
関連する問題