UICollectionView layout for paging navigation with header, which contains titles and selection marker on it.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Sundial is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Sundial'
Sundial layout integrated in the same with regular UICollectionViewLayout:
let collectionView = CollectionView<CollectionViewPagerSource>()
collectionView.source.pager = self
collectionView.collectionViewLayout = CollectionViewLayout(hostPagerSource: collectionView.source) { [weak self] in
return ["Title1", "Title2", "Title3"]
}
The only thing you need to do is to return array of titles and provide implementation of Selectable
protocol. Pager sources of Astrolabe are conforms to this protocols out of box.
Sundial provides basic UI and behavior customization over Setting structure:
public struct Settings {
public var stripHeight: CGFloat
public var markerHeight: CGFloat
public var itemMargin: CGFloat
public var bottomStripSpacing: CGFloat
public var backgroundColor: UIColor
public var anchor: Anchor
public var inset: UIEdgeInsets
public var alignment: PagerHeaderSupplementaryAlignment
public var pagesOnScreen: Int
public var jumpingPolicy: JumpingPolicy
}
Cool feature of Sundial is 'jumping'. You can set jumping policy to skip pages when you are switching between pages which located far from each other and it looks like you are switching between neighbors:
Here is the list of possible anchors:
public enum Anchor {
case content
case centered
case fillEqual
case equal(size: CGFloat)
case left(offset: CGFloat)
case right(offset: CGFloat)
}
Content | Centered |
---|---|
Left | Fill equal |
Here is definition of default decoration view in Sundial layout:
public typealias DecorationView = GenericDecorationView<TitleCollectionViewCell, MarkerDecorationView<TitleCollectionViewCell.Data>, DecorationViewAttributes<TitleCollectionViewCell.Data>>
public typealias CollectionViewLayout = GenericCollectionViewLayout<DecorationView>
public typealias CollapsingCollectionViewLayout = GenericCollapsingCollectionViewLayout<DecorationView>
As you can see here is possible to configure default decoration view itself providing another classes of TitleCell
or MarkerCell
. Or if necessary for your project decoration view itself if you need to provide another type decoration view conforming DecorationViewPageable
protocol. For example:
typealias CustomDecoration = GenericDecorationView<CustomTitleCollectionViewCell, CustomMarkerDecorationView, DecorationViewAttributes<CustomTitleCollectionViewCell.Data>>
typealias CustomLayout = GenericCollectionViewLayout<CustomDecoration>
Sundial also has layout for collapsing header - CollapsingCollectionViewLayout
. Creation is almost the same with CollectionViewLayout
. The only difference, that you need to provide implemenetations of CollapsingItem
protocol.
let collectionView = CollectionView<CollectionViewPagerSource>()
typealias Layout = CollapsingCollectionViewLayout
let items = [controller1, controller2, controllerLoader, controller4, controller5]
let layout = Layout(items: items, hostPagerSource: collectionView.source) { [weak self] in
return self?.titles ?? []
}
Example of CollapsingItem
implementation:
class TestViewController: UIViewController, Accessor, CollapsingItem {
let visible = BehaviorRelay<Bool>(value: false)
var scrollView: UIScrollView {
return containerView
}
Here is the result:
When you are using content based anchor, you must provide one of Distribution
value:
public enum Distribution {
case left, right, center, proportional, inverseProportional, equalSpacing
}
When content of provided titles are not fit into header width, titles will be distributed according to provided distribution.
Content size of title is taking from title cell. Default implementation is TitleCollectionViewCell
. If you need to provide custom size, you have to implement your own cell and provide custom Data
which will implement Titleable
protocol.
- More anchors
- Ability to scroll UICollectionView inside decoration view
Sundial is available under the MIT license. See the LICENSE file for more info.