TTBaseUICollectionView

Core

A UICollectionView subclass with sensible defaults: transparent background, hidden scroll indicators, automatic content inset for navigation bar, and reloadAsyncData() for safe background-thread data reloads.


🚀 Usage

// Default: clear bg, hidden indicators, content inset set
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
layout.minimumInteritemSpacing = 8
layout.minimumLineSpacing = 8

let collectionView = TTBaseUICollectionView(collectionViewLayout: layout)
collectionView.dataSource = self
collectionView.delegate = self

// Custom bg and scroll settings
let cv = TTBaseUICollectionView(
    collectionViewLayout: layout,
    bgColor: .systemGroupedBackground,
    isShowCroll: false,
    isSetContent: true
)

// Async-safe reload (call from any thread)
viewModel.onDataUpdated = { [weak self] in
    self?.collectionView.reloadAsyncData()
}

📖 API Reference

MemberTypeDescription
bgColorUIColorBackground color (default: .clear)
isShowScrollIndicatorBoolShow/hide both scroll bars (default: false)
isSetContentInsetBoolAuto-set top inset to account for nav bar (default: true)
reloadAsyncData()MethodDispatches reloadData() on main thread safely
setBgColor(color:)MethodSet background color after init
Pro Tip: Always use reloadAsyncData() instead of calling reloadData() directly when updating from a network callback or background queue — it guarantees the reload happens on the main thread without crashing.