This file contains hidden or 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
func collectionView(_ collectionView: UICollectionView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] | |
{ | |
let item = self.items[indexPath.row] | |
let itemProvider = NSItemProvider(object: item as NSString) | |
let dragItem = UIDragItem(itemProvider: itemProvider) | |
dragItem.localObject = item | |
return [dragItem] | |
} |
This file contains hidden or 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
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool | |
{ | |
return true | |
} | |
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) | |
{ | |
let item = self.items[sourceIndexPath.row] | |
self.items.remove(at: sourceIndexPath.row) | |
self.items.insert(item, at: destinationIndexPath.row) |
This file contains hidden or 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
func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator) | |
{ | |
let destinationIndexPath: IndexPath | |
if let indexPath = coordinator.destinationIndexPath | |
{ | |
destinationIndexPath = indexPath | |
} | |
else | |
{ | |
// Get last index path of collection view. |
This file contains hidden or 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
collectionView.performBatchUpdates({ | |
var indexPaths = [IndexPath]() | |
for (index, item) in coordinator.items.enumerated() | |
{ | |
//Destination index path for each item is calculated separately using the destinationIndexPath fetched from the coordinator | |
let indexPath = IndexPath(row: destinationIndexPath.row + index, section: destinationIndexPath.section) | |
self.items.insert(item.dragItem.localObject as! String, at: indexPath.row) | |
indexPaths.append(indexPath) | |
} | |
collectionView.insertItems(at: indexPaths) |
This file contains hidden or 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
let items = coordinator.items | |
if items.count == 1, let item = items.first, let sourceIndexPath = item.sourceIndexPath | |
{ | |
var dIndexPath = destinationIndexPath | |
if dIndexPath.row >= collectionView.numberOfItems(inSection: 0) | |
{ | |
dIndexPath.row = collectionView.numberOfItems(inSection: 0) - 1 | |
} | |
collectionView.performBatchUpdates({ | |
self.items.remove(at: sourceIndexPath.row) |
This file contains hidden or 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
func collectionView(_ collectionView: UICollectionView, dragPreviewParametersForItemAt indexPath: IndexPath) -> UIDragPreviewParameters? | |
{ | |
let previewParameters = UIDragPreviewParameters() | |
previewParameters.visiblePath = UIBezierPath(rect: CGRect(x: 25, y: 25, width: 120, height: 120)) | |
return previewParameters | |
} | |
This file contains hidden or 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
let items = coordinator.items | |
var dIndexPath = destinationIndexPath | |
if dIndexPath.row >= collectionView.numberOfItems(inSection: 0) | |
{ | |
dIndexPath.row = collectionView.numberOfItems(inSection: 0) - 1 | |
} | |
var sourceIndexPaths = [IndexPath]() | |
var destinationIndexPaths = [IndexPath]() | |
for item in items | |
{ |
This file contains hidden or 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
let gradientLayer = CAGradientLayer() | |
gradientLayer.colors = [UIColor.purple.cgColor, UIColor.yellow.cgColor] | |
gradientLayer.startPoint = CGPoint(x: 0, y: 0) | |
gradientLayer.endPoint = CGPoint(x: 1, y: 1) | |
gradientLayer.frame = view.bounds |
This file contains hidden or 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
@IBDesignable class DesignableView: UIView | |
{ | |
@IBInspectable var gradientColor1: UIColor = UIColor.white { | |
didSet{ | |
self.setGradient() | |
} | |
} | |
@IBInspectable var gradientColor2: UIColor = UIColor.white { | |
didSet{ |
This file contains hidden or 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
class CustomCollectionViewCell: UICollectionViewCell | |
{ | |
//Gradient to add in the cell | |
private lazy var gradient: CAGradientLayer = { | |
let gradientLayer = CAGradientLayer() | |
gradientLayer.colors = [UIColor.darkGray.cgColor, UIColor.orange.cgColor] | |
gradientLayer.startPoint = CGPoint(x: 0, y: 0) | |
gradientLayer.endPoint = CGPoint(x: 1, y: 1) | |
gradientLayer.frame = self.bounds | |
return gradientLayer |