Skip to content

Instantly share code, notes, and snippets.

View pstasiak's full-sized avatar

Przemysław Stasiak pstasiak

  • Tooploox
  • Warsaw
View GitHub Profile
@pstasiak
pstasiak / UICollectionView+DragInitationTime.swift
Last active October 26, 2020 10:40
Setting custom drag gesture initiation time. Important: Should be called after each update of `dragDelegate`.
import UIKit
extension UICollectionView {
func setupDragInitiationTime(_ time: TimeInterval) {
let dragInitiatingRecognizerName = "dragInitiation"
let longPressRecognizers = gestureRecognizers?.compactMap {
$0 as? UILongPressGestureRecognizer
} ?? []
let dragInitiatingRecognizers = longPressRecognizers.filter {
@pstasiak
pstasiak / UIButton+SelectionToggling.swift
Created July 10, 2017 13:20
Adds to UIButton selecting / deselecting on touch up feature. Useful for checkmark / agreements buttons.
extension UIButton {
var isTogglingSelection: Bool {
get {
return target(forAction: #selector(_touchedInside), withSender: self) != nil
}
set {
if isTogglingSelection {
addTarget(self, action: #selector(_touchedInside), for: .touchUpInside)
} else {