Search code examples
iosswiftbuttonclickuiswitch

Button to replace a switch


I have a table view controller consisting of a list of colors. I want the user to be able to star which colors he or she likes the most. I currently am using switches to do this, but I want something more visually appealing. I think a button might work. However, I want the button to have similar properties to the switch (ex: isOn property). How might I do this?


Solution

  • UIButtons also have a switch like functionality.

    In IB, set a different image in Interface Builder for the "Selected State Configuration".

    Then, add this in your @IBAction of your button (where "button" is the name of your button):

    self.button.selected = !self.button.selected