【发布时间】:2021-03-13 17:29:45
【问题描述】:
我需要像这样根据标签文本更改collectionview单元格宽度
为此我给了collectionview约束
top, leading, trailing, = 10 height = 80
在单元格中,我在 uiview 中放置了标签,我放置了 uiview,因为我需要给角落半径
和代码
class SearchFilterVC: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
var textArray = ["hbdhwebhj", "behgwfhjewgbkfjbe", "hbhjs", "bdhsbfhegu", "gwdgyqwuguq"]
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 5
self.collectionView.collectionViewLayout = layout
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return textArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SearchFilterCollectionViewCell", for: indexPath as IndexPath) as! SearchFilterCollectionViewCell
cell.textLabel.text = textArray[indexPath.row]
return cell
}
}
编辑:
o/p
如何解决这个问题,请提供代码帮助
【问题讨论】:
标签: swift uicollectionview label width