- Swift
- 此版本暂不支持可编辑标签,如有编辑标签需求,请先使用1.2.2版本。
- 1.2.2版本使用说明请点击此处1.2.2使用说明
- Swift 3.0:
pod 'ACTagView', '~> 2.0.1'
- Swift 4.0:
pod 'ACTagView', '~> 2.2.4'
- Swift 4.2:
pod 'ACTagView', '~> 2.2.6'
- Swift 5.0:
pod 'ACTagView', '~> 2.3.0'
Then, run the following command:
$ pod install
ACTagConfig.default.selectedTagBackgroundColor = UIColor.white // tag选中背景色
ACTagConfig.default.selectedTagBorderColor = UIColor.red // tag选中边框颜色
ACTagConfig.default.selectedTagTextColor = UIColor.red // tag选中文字颜色
ACTagConfig.default.tagBackgroundColor = UIColor.white // tag背景色
ACTagConfig.default.tagBorderColor = UIColor.black // tag边框颜色
ACTagConfig.default.tagTextColor = UIColor.black // tag文字颜色
...
let tagsStrList = ["我喜欢", "胸大", "腿长"]
var autoLineFeedTagView = ACTagView(frame: CGRect(x: 0, y: 100, width: UIScreen.main.bounds.width, height: 100), layoutType: .autoLineFeed)
autoLineFeedTagView.tagDataSource = self
autoLineFeedTagView.tagDelegate = self
autoLineFeedTagView.allowsMultipleSelection = true // 是否支持多选
autoLineFeedTagView.backgroundColor = UIColor.white
print(autoLineFeedTagView.estimatedHeight) // 打印预估高度
view.addSubview(autoLineFeedTagView)
let tagsStrList = ["我喜欢", "胸大", "腿长"]
var oneLineTagView = ACTagView(frame: CGRect(x: 0, y: 300, width: UIScreen.main.bounds.width, height: 50), layoutType: .oneLine)
oneLineTagView.tagDataSource = self
oneLineTagView.tagDelegate = self
oneLineTagView.backgroundColor = UIColor.white
view.addSubview(oneLineTagView)
extension TagViewController: ACTagViewDataSource {
func numberOfTags(in tagView: ACTagView) -> Int {
return tagsStrList.count
}
func tagView(_ tagView: ACTagView, tagAttributeForIndexAt index: Int) -> ACTagAttribute {
let tag = ACTagAttribute(text: tagsStrList[index])
return tag
}
}
extension TagViewController: ACTagViewDelegate {
func tagView(_ tagView: ACTagView, didSelectTagAt index: Int) {
print(index)
print("selectedTagsList-----------", tagView.indexsForSelectedTags) // 打印所有已选中标签的下标
}
func tagView(_ tagView: ACTagView, didDeselectTagAt index: Int) {
print("deselected------------",index)
}
}
- 使用xib关联时,必须在
awakeFromNib
方法中调用标签View的initTagView(layoutType: ACTagViewLayoutType)
方法