【发布时间】:2014-12-10 19:50:18
【问题描述】:
我有一个UICollextionView,它目前计算出UILabel 的高度。每个标签都有自己的高度。我现在想对集合视图单元做同样的事情。我似乎只能将它们全部更改为相同的。我该怎么办?谢谢
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as ChatCellCollectionViewCell
cell.backgroundColor = UIColor.whiteColor()
cell.layer.cornerRadius = 10
cell.textLabel.text = "\(messageArray[indexPath.row])"
cell.nameLabel.text = "\(namesArray[indexPath.row])"
cell.textLabel.numberOfLines = 0
cell.textLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping
frame = cell.textLabel.frame
cell.textLabel.sizeToFit()
frame.size.height = cell.textLabel.frame.size.height
cell.textLabel.frame = frame
return cell
}
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell