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
dataSource.supplementaryViewProvider = { collectionView, kind, indexPath -> UICollectionReusableView? in | |
switch kind { | |
case UICollectionView.elementKindSectionHeader: | |
guard let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sampleHeaderIdentifier", for: indexPath) as? SampleCollectionReusableView else { | |
fatalError("Header is not registered") | |
} | |
headerView.fill(with: "My Awesome Colours") | |
return headerView |
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 colors: [UIColor] = [ | |
.brown, | |
.purple, | |
.systemBlue, | |
.systemRed, | |
.systemGray, | |
.systemPink | |
] |
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 = colors.shuffled() | |
snapshot.appendItems(items, toSection: 0) | |
dataSource.apply(snapshot, animatingDifferences: true) |
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
enum Section: CaseIterable { | |
case firstSection | |
case secondSection | |
} | |
... | |
var snapshot = NSDiffableDataSourceSnapshot<Section, UIColor>() | |
snapshot.appendSections(.firstSection) | |
snapshot.appendSections(.secondSection) | |
... | |
``` |
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
var snapshot = NSDiffableDataSourceSnapshot<Int, UIColor>() | |
snapshot.appendSections([0]) | |
snapshot.appendItems(items, toSection: 0) |
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 dataSource = UICollectionViewDiffableDataSource<Int, UIColor>(collectionView: collectionView) { collectionView, indexPath, item in | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sampleIdentifier", for: indexPath) | |
cell.backgroundColor = item | |
return cell | |
} |
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
//: A UIKit based Playground for presenting user interface | |
import UIKit | |
import PlaygroundSupport | |
final class SampleCollectionReusableView: UICollectionReusableView { | |
private let titleLabel = UILabel() | |
override init(frame: CGRect) { | |
super.init(frame: frame) |
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
override var isHighlighted: Bool { | |
didSet { | |
UIView.animate(withDuration: 0.25, delay: 0, options: [.curveEaseInOut], animations: { | |
if self.isHighlighted { | |
self.cardView.transform = CGAffineTransform(scaleX: 0.95, y: 0.95) | |
} else { | |
self.cardView.transform = CGAffineTransform.identity | |
} | |
}, completion: nil) | |
} |
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
struct SearchView: View { | |
let array = "SwiftUI is great but some views might need an extra work".components(separatedBy: " ") | |
@State private var searchText = "" | |
var body: some View { | |
VStack { | |
SearchBar(text: $searchText) | |
List { |
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
.gesture(DragGesture().onChanged { _ in | |
UIApplication.shared.endEditing(true) | |
}) |
NewerOlder