UI组件库 活跃维护

CollectionViewSlantedLayout

yacir/CollectionViewSlantedLayout

一个显示倾斜单元格的 CollectionView 布局

2339
Stars 标星
136
Forks 分支
37
Watchers 关注
3
Open Issues
Swift
主要语言
MIT
开源协议
44.1 MB
仓库大小
5 年前
最后推送
一键安装扩展 / 插件指令
dsh plugin --profile web add github:yacir/CollectionViewSlantedLayout
git clone https://github.com/yacir/CollectionViewSlantedLayout.git
git clone git@github.com:yacir/CollectionViewSlantedLayout.git
README.md master

英文原文正文为项目原始 README(英文),本站后续会翻译为中文,当前仅剔除图片与无关章节并统一排版。


CollectionViewSlantedLayout is a subclass of the UICollectionViewLayout allowing the display of slanted cells in a UICollectionView.

功能

  • Pure Swift 5.
  • Works with every UICollectionView.
  • Horizontal and vertical scrolling support.
  • Dynamic cells height
  • Fully Configurable

安装

CocoaPods

CollectionViewSlantedLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:

use_frameworks!
pod 'CollectionViewSlantedLayout', '~> 3.1'

Carthage

You can also install it via Carthage. To do so, add the following to your Cartfile:

github 'yacir/CollectionViewSlantedLayout'

使用

  1. Import CollectionViewSlantedLayout module to your controller

    import CollectionViewSlantedLayout
  2. Create an instance and add it to your UICollectionView.

    let slantedSayout = CollectionViewSlantedLayout()
    UICollectionView(frame: .zero, collectionViewLayout: slantedSayout)
  3. Use the CollectionViewSlantedCell class for your cells or subclass it.

Find a demo in the Examples folder.

属性

  • slantingSize:

    @IBInspectable var slantingSize: UInt

    The slanting size. The default value of this property is 75.

  • slantingDirection:

    var slantingDirection: SlantingDirection

    The slanting direction. The default value of this property is upward.

  • slantingAngle:

    fileprivate(set) var slantingAngle: CGFloat

    The angle, in radians, of the slanting. The value of this property could be used to apply a rotation transform on the cell's contentView in the collectionView(_:cellForItemAt:) method implementation.

    if let layout = collectionView.collectionViewLayout as? CollectionViewSlantedLayout {
        cell.contentView.transform = CGAffineTransform(rotationAngle: layout.rotationAngle)
    }
  • scrollDirection:

    var scrollDirection: UICollectionViewScrollDirection

    The scroll direction of the grid. The grid layout scrolls along one axis only, either horizontally or vertically. The default value of this property is vertical.

  • isFirstCellExcluded:

    @IBInspectable var isFirstCellExcluded: Bool

    Set it to true to disable the slanting for the first cell. The default value of this property is false.

  • isLastCellExcluded:

    @IBInspectable var isLastCellExcluded: Bool

    Set it to true to disable the slanting for the last cell. The default value of this property is false.

  • lineSpacing:

    @IBInspectable var lineSpacing: CGFloat

    The spacing to use between two items. The default value of this property is 10.0.

  • itemSize:

    @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.

  • zIndexOrder:

    var zIndexOrder: ZIndexOrder

    The zIndex order of the items in the layout. The default value of this property is ascending.

协议

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:

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.

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 a fixed set of sizes or dynamically adjust the sizes based on the cell’s content.

作者

Yassir Barchi

致谢

This framework is inspired by this prototype released by Matt Bridges.

许可证

CollectionViewSlantedLayout is available under the MIT license. See the LICENSE file for more info.

本站来源与版权声明
  • 本文标题:CollectionViewSlantedLayout - 一个显示倾斜单元格的 CollectionView
  • 本文链接:https://www.cn121.com/uikit/yacir-collectionviewslantedlayout.html
  • 原项目:yacir/CollectionViewSlantedLayout 版权归原作者 yacir 及贡献者所有
  • 收录信息:本站于 2026-11-22 收录本项目,本页所列协议与仓库指标均为收录当时的状态;该日期之后原项目的版本更新与协议变更,本页不作同步。
  • 开源协议:收录时本项目采用 MIT(查看 LICENSE 原文),本站转载其原始文档(未改动文字,仅剔除图片与无关章节);使用、修改、分发请以该仓库 LICENSE 原文为准。
  • 站点出处:本文首发于 OneTwoOne,收录自 GitHub 开源项目 yacir/CollectionViewSlantedLayout。
  • 内容说明:本页正文为原项目 README 原文(英文),本站后续会翻译为中文(当前尚未译出,仅将二级标题译为中文,便于按栏目定位;标题原文可在下方原仓库中查看),仅剔除了图片与赞助等无关章节、并把相对链接改为绝对地址;页首简介为机器翻译自仓库描述。
  • 引用声明:商业转载、第三方聚合或 AI 检索训练引用时,请务必保留以上来源出处、本文永久链接,以及原项目的版权声明与许可信息。
  • 下架通道:若原项目此后变更或收紧了许可协议、或作者/权利人认为本站的收录方式(译文、排版适配、简介翻译等)超出其授权范围,请通过 xyd3302001@163.com 发送下架通知,并附上项目地址与本页链接。本站核实后将第一时间删除本页内容,或改为不复制原文的目录性收录;署名更正等其他要求可一并提出。