DragSelectCollectionView
public class DragSelectCollectionView: UICollectionView
A UICollectionView subclass that enables contiuous selection of cells while dragging.
Use this class as you would use a regular instance of UICollectionView, i.e. with a
UICollectionViewDataSource and a UICollectionViewDelegate. Call beginDragSelection(at:) when
you want to start a continuous selection event starting at a particular IndexPath. Throughout the selection
process, this class will ask its delegate if it should select / deselect each cell it encounters.
-
Sets a maximum number of cells that may be selected,
nilby default. Setting this value to a value of0or lower effectively disables selection. Setting this value tonilremoves any upper limit to selection. If when setting a new value, the collection view already has a greater number of cells selected, then the apporpriate number of cells will be deselected from the end of the list.Declaration
Swift
public var selectionLimit: Int? -
Height of top and bottom hotspots for auto scrolling. Defaults to
100. Set this to0to disable auto scrolling.Declaration
Swift
public var hotspotHeight: CGFloat = 100 -
Padding between top of collection view and top hotspot. Defaults to
0.Declaration
Swift
public var hotspotOffsetTop: CGFloat = 0 -
Padding between bottom of collection view and bottom hotspot. Defaults to
0.Declaration
Swift
public var hotspotOffsetBottom: CGFloat = 0 -
Used to calculate auto scroll speed. Defaults to
0.5. Auto scroll speed is calculated asbaseAutoScrollVelocitytimes however many points into the hotspot the user has touched, per0.025seconds. For example, if the user has traversed5points from the middle of the screen into either of the hotspot, and this value is0.5, then the velocity will be0.5 * 5 / 0.025 = 100points/second.Declaration
Swift
public var baseAutoScrollVelocity: CGFloat = 0.5 -
Toggles selection and scrolling information output to console. Defaults to
false.Declaration
Swift
public static var logging = false -
Toggles whether to show a faded green view where the hotspots are. Defaults to
false. Useful for debugging.Declaration
Swift
public var showHotspots = false
-
Attempts to begin drag selection at the provided index path.
Declaration
Swift
@discardableResult public func beginDragSelection(at selection: IndexPath) -> BoolParameters
selectionthe index path at which to begin drag selection.
Return Value
falseif drag selection is alreay in progress orselectioncannot be selected (decided by theUICollectionViewDelegate),trueotherwise. -
Attempts to select all items, starting from the first item in the collection. If an item cannot be selected (decided by the
UICollectionViewDelegate), the item is skipped. IfselectionLimitis reached, this method terminates. ThecollectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)method of theUICollectionViewDelegateis called for each selected item.Declaration
Swift
public func selectAll() -
Deselects all selected items. The
collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath)method of theUICollectionViewDelegateis called for each deselected item.Declaration
Swift
public func deselectAll()
View on GitHub
DragSelectCollectionView Class Reference