【发布时间】:2016-11-10 13:33:38
【问题描述】:
问题是每个单元格都有不同的 UILabel 内容,我希望单元格的宽度固定,高度灵活,具体取决于 UILabel hight 的内容,我尝试了针对这个问题的不同解决方案并观看了几个教程但是不幸的是,它对我没有锻炼。
**我有一个视图控制器和两个集合视图 我只需要其中一个有一个灵活的高度**
extension TextViewController : UICollectionViewDelegateFlowLayout {
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
if collectionView == PagesCollectionView
{
return CGSizeMake(44.0, 44.0)
}
else {
width = UIScreen.mainScreen().bounds.width - CGFloat( 14 )
return CGSizeMake( width , hight )
}
}
编辑 1:
有没有像在表格视图中那样的简单方法?
示例:-
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension }
【问题讨论】:
-
检查此链接可能会对您有所帮助stackoverflow.com/questions/27285258/…
-
Thx,这是一个很好的方法,但不是我需要的,我希望高度等于标签高度。是否可以从这个乐趣中访问 cell.label.hight ?我试图访问它,但不知道该怎么做。
标签: swift autolayout ios9 uicollectionviewcell