willowtreeapps / dynamic-type

MIT License
0 stars 1 forks source link

Add helpers for UITableView and UICollectionView #6

Open ianterrell opened 7 years ago

ianterrell commented 7 years ago

Add a helper to update fonts on visible cells if the cells conform to RespondsToDynamicFont.

kent-white commented 7 years ago

The helper would have to be on the view controller though right? Not on the collection view

ianterrell commented 7 years ago

My intention in this ticket was to add helpers to the collection view, so that the implementation on the controller would be more straightforward.

So, not replacing the controller implementation, but simplifying it from:

func updateFonts(preferredContentSize: UIContentSizeCategory) {
    guard let cells = collectionView?.visibleCells else { return }
    for cell in cells {
        guard let cell = cell as? RespondsToDynamicFont else { continue }
        cell.updateFonts(preferredContentSize: preferredContentSize)
    }
    collectionView?.collectionViewLayout.invalidateLayout()
}

to

func updateFonts(preferredContentSize: UIContentSizeCategory) {
    collectionView?.updateFonts(preferredContentSize: preferredContentSize)
    collectionView?.collectionViewLayout.invalidateLayout()
}