TagCellLayout 1.0

TagCellLayout 1.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2018年1月
SwiftSwift 版本4.0
SPM支持 SPM

Ritesh 维护。



  • Ritesh Gupta

TagCellLayout

关于

这是一个ui-collection-view布局类,它负责处理后端所有制作标签的逻辑,使用UICollectionView。它还允许您调整布局的对齐方式,即左、中或右。现在您只需要关注您的标签视图即可。

安装

要使用CocoaPods将TagCellLayout集成到您的Xcode项目中,请在Podfile中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'TagCellLayout', '~> 0.2'

截图

Center Alignment Left Alignment Right Alignment

用法

  • 初始化方法
import TagCellLayout

let tagCellLayout = TagCellLayout(tagAlignmentType: .Center, delegate: self)
collectionView.collectionViewLayout = tagCellLayout
  • 标签对齐

tagAlignmentType可以是左、中心或右。如果是nil,则默认为左对齐。

  • 辅助方法

- func textWidth(text: String, font: UIFont) -> CGFloat

它计算一个标签字符串的宽度。

代理方法

  • 必须遵守的协议:TagCellLayoutDelegate

  • 方法

- func tagCellLayoutTagWidth(layout: TagCellLayout, atIndex index:Int) -> CGFloat
- func tagCellLayoutTagFixHeight(layout: TagCellLayout) -> CGFloat

架构

  • tagCellLayoutTagFixHeight(layout: TagCellLayout)

它只会被调用一次,因为所有标签都有一个固定的高度,这个高度将由该方法定义。

  • tagCellLayoutTagWidth(layout: TagCellLayout, atIndex index:Int)

它会对每个标签调用一次,此时您将计算它们的宽度,然后将它们传递给TagCellLayout类以进行进一步的计算。

  • collectionView.numberOfItemsInSection(0)

内部,标签的数量将通过上述方法计算。

贡献力量

在此提交问题或发送pull request。

许可证

TagCellLayout在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。