AnKit is an UIKit wrapper library written in pure Swift
import AnKit
import UIKit
final class SimpleVC: UIViewController {
private lazy var collectionView = CollectionView()
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
fillCollectionView()
}
}
private extension SimpleVC {
func setupUI() {
view.backgroundColor = .systemBackground
view.addSubview(collectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
collectionView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
collectionView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
collectionView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
collectionView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
])
}
func makeItem(text: String) throws -> CollectionViewItem {
try PlainLabelItem(
text: text,
textColor: .label,
textFont: .preferredFont(forTextStyle: .title1),
tintColor: .systemIndigo,
textAlignment: .center,
textInsets: NSDirectionalEdgeInsets(
horizontalInset: .defaultHorizontalOffset,
verticalInset: 8
),
dividerModel: .lineDefaultOffsetFromStart(color: .systemRed)
)
}
func fillCollectionView() {
do {
let section = try PlainListSection(
items: [
try makeItem(text: "Text 1"),
try makeItem(text: "Text 2"),
try makeItem(text: "Text 3"),
try makeItem(text: "Text 4"),
try makeItem(text: "Text 5")
]
)
try collectionView.set(
sections: [section],
animatingDifferences: false
)
} catch {
assertionFailure(error.localizedDescription)
}
}
}There is more examples in Playground folder, just go and see it
-
UICollectionViewDiffableDataSourcewrappers for easy use ViewModel-View pattern in Swift way -
UICollectionViewCompositionalLayoutwrappers for easy useUICollectionViewin all your screens - Ready plain sections, spacer, shimmer & label items
-
UICollectionViewDataSourcePrefetchingsupport - Additional
UIKitwrappers for constraints, blurred views, layer shadows and others
You can create custom sections and do any layout what you want.
Just create new class, inherit it from CollectionViewSection and override layoutConfiguration method to implement.
For example, see PlainListSection in Sources folder.
You can create custom items and do any cells, which inherits from CollectionViewCell.
Just create new class, inherit it from CollectionViewItem and override cellType property to implement.
For example, see PlainLabelItem in Sources folder.
You can create custom items and do any supplementary views, which inherits from CollectionViewSupplementaryView.
Just create new class, inherit it from CollectionViewSupplementaryItem and override supplementaryViewType property to implement.
For example, see PlainLabelBoundarySupplemetaryItem in Sources folder.
You can create custom background items for each section in your collection view.
Just create new class, inherit it from CollectionViewDecorationItem and override decorationViewType property to implement.
For example, see SecondarySystemGroupedBackgroundDecorationItem in Sources folder.
You can provide custom transaction to collection view's snapshot data.
Just call apply(snapshotTransaction:animatingDifferences:) method
and pass to snapshotTransaction parameter any array of CollectionView.SnapshotAction.
Also, there is BaseVC for convenient methods, which you could need in your UIViewControllers.
Just inherit BaseVC in your view controller.
For example, see ShuffleItemsVC and SectionBackgroundVC in Playground folder.
See more screen examples in Playground folder.
iOS 13.0+
- Download
AnKitproject - Open
.xcodeprojfile, chooseCreate-XCFramework-scriptstarget and press build target (by default key bindings clickcommand + B) - After success build it will open folder with built
.xcframeworkbinary file - Open your
.xcodeprojfile - Go to
Project Navigator(by default key bindings clickcommand + 1) - Click on your project
- Go to
Your target->Generaltab - Drag that
.xcframeworkbinary file inFramework, Librariessection - Build your project (by default key bindings click
command + B) - Write
import AnKitin your Swift file - Enjoy
After once you added link to
.xcframeworkinFramework,Librariessection, you can delete previous version and just copy.xcframeworkbinary file into same place in your project, where previous.xcframeworkbinary lay, cleanDerivedDatafolder and build your project. New changes will work automatically.
- Just copy & link sources into your project (for better use, in standalone folder)
AnKit is released under the MIT license. See LICENSE for details.
Andrey Popov (Anvipo)
My e-mail: [email protected]
My Telegram: @Anvipo (https://t.me/Anvipo)