Created
December 10, 2014 06:57
-
-
Save dduan/3fe5f535d8ce3f2397d4 to your computer and use it in GitHub Desktop.
A Deselectable UISegmentedControl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class DeselectableSegmentedControl: UISegmentedControl { | |
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) { | |
let previouslySelectedIndex = self.selectedSegmentIndex | |
super.touchesEnded(touches, withEvent: event) | |
if previouslySelectedIndex == self.selectedSegmentIndex { | |
self.selectedSegmentIndex = UISegmentedControlNoSegment | |
self.sendActionsForControlEvents(UIControlEvents.ValueChanged) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment