Updated 29 November 2023
CollectionViewSlantedLayout
Slanted Layout is a subclass of the UICollectionViewLayout allowing the display of slanted cells in a UICollectionView, either horizontally or vertically.
CollectionViewSlantedLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:
1 |
pod 'CollectionViewSlantedLayout', '~> 3.1' |
CollectionViewSlantedLayout
module to your controller
1 |
import CollectionViewSlantedLayout |
UICollectionView
.
1 |
let slantedSayout = CollectionViewSlantedLayout() UICollectionView(frame: .zero, collectionViewLayout: slantedSayout) |
CollectionViewSlantedCell
class either your cells or subclass it.
1 |
@IBInspectable var slantingSize: UInt |
1 |
var slantingDirection: SlantingDirection |
upward
.
1 |
fileprivate(set) var slantingAngle: CGFloat |
collectionView(_:cellForItemAt:)
method implementation, either horizontally or vertically.
1 |
if let layout = collectionView.collectionViewLayout as? CollectionViewSlantedLayout { cell.contentView.transform = CGAffineTransform(rotationAngle: layout.rotationAngle) } |
1 |
var scrollDirection: UICollectionViewScrollDirection |
vertical
1 |
@IBInspectable var isFirstCellExcluded: Bool |
true
to disable the slanting for the first cell. The default value of this property is false
.
1 |
@IBInspectable var isLastCellExcluded: Bool |
true
to disable the slanting for the last cell. The default value of this property is false
.
1 |
<span class="pl-k">@IBInspectable</span> <span class="pl-k">var</span> lineSpacing<span class="pl-k">:</span> CGFloat |
The spacing to use between two items. The default value of this property is 10.0
.
1 |
@IBInspectable var itemSize: CGFloat |
The default size to use for cells. If the delegate does not implement the collectionView(_:layout:sizeForItemAt:)
method, the slanted layout uses the value in this property to set the size of each cell. This results in cells that all have the same size. The default value of this property is 225
.
1 |
var zIndexOrder: ZIndexOrder |
The zIndex order of the items in the layout. The default value of this property is ascending
.
The grid layout scrolls along one axis only, either horizontally or vertically
The CollectionViewDelegateSlantedLayout
protocol defines methods that let you coordinate with a CollectionViewSlantedLayout
object to implement a slanted layout. The CollectionViewDelegateSlantedLayout
protocol has the following methods:
1 |
optional func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: CollectionViewSlantedLayout, sizeForItemAt indexPath: IndexPath) -> CGFloat |
This method asks the delegate for the size of the specified item’s cell, either horizontally or vertically
If you do not implement this method, the slanted layout uses the values in its itemSize
property to set the size of items instead.
Your implementation of this method can return either a fixed set of sizes or dynamically adjust the sizes based on the cell’s content, either horizontally or vertically
For more blogs please click here.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.