I'm creating a suggestion/tags view. Which is basically a horizontal uicollectionview
. I've a custom cell in which I just have one label with no autoresizing or auto constraints. And I've an array var tagsArray = ["Label", "A Long Label", "A very long label"]
which I am using in the collectionView delegate methods as:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return tagsArray.count
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let size = (tagsArray[indexPath.row] as NSString).size(withAttributes: nil)
return size
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TagCell", for: indexPath) as! TagCollectionViewCell
cell.tagLabel.text = tagsArray[indexPath.row]
return cell
}
The second function collectionViewLayout
is something that I've picked form stack overflow but when I run it there is no effect on the UILabel.