测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2018年1月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由 Ritesh 维护。
这是一个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'
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文件。