Option 1:
Create a custom control with this button, create a logical property like isSelected . Add a collection of such controls to your ViewController, hang up the action to click. When clicking, put the desired isSelected status to the one you clicked on, then go through all the elements of the collection and check that they have the correct status. (because only one can be active)
This option is quite beautifully solved through RxSwift + MVVM, but it will probably be difficult for a beginner.
Option 2:
Use UISegmentedControl .
This control can only have one element a priori active, use the selectedSegmentIndex property. Poshaman a little with visual display, will be very similar to what you drew.
An example of a solution to the forehead:
class ViewController: UIViewController { @IBOutlet weak var buttonHiragana: UIButton! @IBOutlet weak var buttonKatagana: UIButton! @IBOutlet weak var buttonEasy: UIButton! @IBOutlet weak var buttonMedium: UIButton! @IBOutlet weak var buttonHard: UIButton! enum difficultyLevel { case Easy case Medium case Hard } var chosenDifficulty: difficultyLevel = .Easy; var isHiraganaChosen: Bool = true; var isKataganaChosen: Bool = true; override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // Стартовые значения скорее всего будут грузится откуда-то из настроек // Сейчас мы их захардкодим self.buttonEasy.backgroundColor = UIColor.green; self.buttonMedium.backgroundColor = UIColor.white; self.buttonHard.backgroundColor = UIColor.white; self.buttonHiragana.backgroundColor = UIColor.green; self.buttonKatagana.backgroundColor = UIColor.green; } @IBAction func buttonHiraganaTapped(_ sender: UIButton) { if (isHiraganaChosen) { if (isKataganaChosen) { isHiraganaChosen = false; self.redrawSingleButton(isChosen: isHiraganaChosen, for: sender) } else { // Тут желательно как-то сообщить ползователю, что так нельзя делать // Можно использовать UIAlertView или что-то еще NSLog("Must have at least one alphabet chosen"); } } else { isHiraganaChosen = true; self.redrawSingleButton(isChosen: isHiraganaChosen, for: sender) } } @IBAction func buttonKataganaTapped(_ sender: UIButton) { if (isKataganaChosen) { if (isHiraganaChosen) { isKataganaChosen = false; self.redrawSingleButton(isChosen: isKataganaChosen, for: sender) } else { // Тут желательно как-то сообщить ползователю, что так нельзя делать // Можно использовать UIAlertView или что-то еще NSLog("Must have at least one alphabet chosen"); } } else { isKataganaChosen = true; self.redrawSingleButton(isChosen: isKataganaChosen, for: sender) } } @IBAction func buttonEasyTapped(_ sender: UIButton) { self.redrawDifficultyButtons(with: .Easy, and: sender); } @IBAction func buttonMediumTapped(_ sender: UIButton) { self.redrawDifficultyButtons(with: .Medium, and: sender) } @IBAction func buttonHardTapped(_ sender: UIButton) { self.redrawDifficultyButtons(with: .Hard, and: sender) } private func redrawSingleButton(isChosen: Bool, for button: UIButton) { if (isChosen) { button.backgroundColor = UIColor.green; } else { button.backgroundColor = UIColor.white; } } private func redrawDifficultyButtons(with difficulty: difficultyLevel, and button: UIButton) { // chosenDifficulty - сейчас старая сложность // difficulty - новая // oldButton - старая активная кнопка // button - новая let oldButton: UIButton; if (self.chosenDifficulty != difficulty) { if (self.chosenDifficulty == .Easy) { oldButton = buttonEasy; } else if (self.chosenDifficulty == .Medium) { oldButton = buttonMedium; } else { oldButton = buttonHard; } self.redrawSingleButton(isChosen: false, for: oldButton); self.redrawSingleButton(isChosen: true, for: button); self.chosenDifficulty = difficulty; } } }