A simple framework with strikethrough applications:
- Add strike through to your string,
- StrikeThroughLabel helps swiping to strike easier
var myLabel = "aaaaaa"
// Add strikethrough
var strikedLabel = myLabel.strikeThrough(.add)
// Remove strikethrough from attributedString
var unStrikedLabel = strikedLabel?.string.strikeThrough(.remove)
// In ViewController
@IBOutlet weak var myLabel: StrikeThroughLabel!
That's all you have to do, by replace UILabel
with StrikethroughLabel
→ Now when you swipe, the strikethough will follow
If you applied to mutiple gesture, make sure to conform to UIGestureRecognizerDelegate
, with below function:
override func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
Make sure to refer to: https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/coordinating_multiple_gesture_recognizers
StrikeThroughLabel use only PanGestureRecognizer, with panning right enable but not left enable.
You can add another Pan Gesture, or change directly into framework code
Inside function handlePan(gesture:) :
xTranslation
> 0: User start swiping from left to right (This is already for swipe to strike through)
xTranslation
< 0 : User start swiping from right to left (Not yet handle)
Download clone and embeded into your project:
- Download
- Drag .xcodeproj into your source
- Embed framework in General → Frameworks and Libraries