-2

I have 2 button like picture below, their text label are: "Input location...". Now i want to click on the swap button on the right, so the text label of these button will swap. It's look like you have 2 location and you want to swap it. Please any one can point me how to do it. Thank you very much.

screenShot

Daniyar
  • 2,975
  • 2
  • 26
  • 39
  • 2
    `NSString *firstStr = [firstLabel text]; [firstLabel setText:[secondLabel text]]; [secondLabel setText:firstStr];` ? "Generic" sample: http://stackoverflow.com/questions/19255069/swap-any-type-of-two-variables-in-c – Larme Oct 14 '16 at 07:47

2 Answers2

1

On click just set their text to each other.

var tempString = secondButton.titleLabel.text
secondButton.setTitle(firstButton.titleLabel.text, forState: UIControlState.Normal)
firstButton.setTitle(tempString, forState: UIControlState.Normal)
mkeremkeskin
  • 644
  • 10
  • 27
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)
}
Callam
  • 11,409
  • 2
  • 34
  • 32