In Interface Builder, select the Attributes Inspector and set the Tag for each button with a unique number, then you can do something like this:
@IBAction changeLanguage(sender: AnyObject) {
guard let button = sender as? UIButton else {
return
}
switch button.tag {
case 1:
// Change to English
case 2:
// Change to Spanish
case 3:
// Change to French, etc
default:
print("Unknown language")
return
}
}
To connect the action to multiple buttons: in Interface Builder, right-click ViewController in the view hierarchy, then left-click to drag the action connection to each button.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…