아래 그림처럼 2 개의 버튼이 있습니다. 텍스트 라벨은 "입력 위치 ..."입니다. 이제 오른쪽의 스왑 버튼을 클릭하고 싶으므로이 버튼의 텍스트 레이블이 바뀝니다. 당신이 2 개의 위치를 가지고 있고 당신이 그것을 바꾸고 싶어하는 것처럼 보입니다. 아무도 나에게 그걸 어떻게 할 수 있는지 가르쳐주세요. 고맙습니다. 클릭에Swift에서 두 버튼의 라벨 텍스트 교체하기
-2
A
답변
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)
}
'는 NSString firstStr을 * = [firstLabel 텍스트]; [firstLabel setText : [secondLabel text]]; [secondLabel setText : firstStr]; '일반'샘플 : http://stackoverflow.com/questions/19255069/swap-any-type-of-two-variables-in-c – Larme