TipUICollectionViewCell
A collection view cell that embeds a tip.
Declaration
@MainActor @objc @preconcurrency final class TipUICollectionViewCellOverview
Use this cell to create a tip you want to display and layout as a UICollectionViewCell. To configure the content and appearance of your cell, use the configureTip(_:arrowEdge:actionHandler:) function and provide a tip along with an optional arrow edge and action handler. Set the background color of your tip view using backgroundColor.
Adding or removing TipUICollectionViewCell is done by listening to a tip’s shouldDisplayUpdates or statusUpdates.
import TipKit
import UIKit
class CatTracksCollectionViewController: UIViewController, UICollectionViewDataSource {
var collectionView: UICollectionView
var catTracksFeatureTip = CatTracksFeatureTip()
override func viewDidLoad() {
super.viewDidLoad()
collectionView.register(TipUICollectionViewCell.self, forCellWithReuseIdentifier: "TipUICollectionViewCell")
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
Task { @MainActor in
for await shouldDisplay in catTracksFeatureTip.shouldDisplayUpdates {
collectionView.reloadData()
}
}
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {
return catTracksFeatureTip.shouldDisplay ? 1 : 0
}
return dataStore.numberOfItemsInSection(section - 1)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let indexPath.section == 0, let catTracksTipCell = collectionView.dequeueReusableCell(withReuseIdentifier: "TipUICollectionViewCell", for: indexPath) as? TipUICollectionViewCell {
catTracksTipCell.configureTip(catTracksFeatureTip)
return catTracksTipCell
}
}
}