【发布时间】:2018-06-19 16:02:55
【问题描述】:
试图计算具有指定宽度的单元格的高度,但无法正确计算。这是一个sn-p。自定义布局指定了两列,它知道列宽。
let cell = TextNoteCell2.loadFromNib()
var frame = cell.frame
frame.size.width = columnWidth // 187.5
frame.size.height = 0 // it does not work either without this line.
cell.frame = frame
cell.update(text: note.text)
cell.contentView.layoutIfNeeded()
let size = cell.contentView.systemLayoutSizeFitting(CGSize(width: columnWidth, height: 0)) // 251.5 x 52.5
print(cell) // 187.5 x 0
return size.height
size 和 cell.frame 都不正确。
单元格内部有一个文本标签,每个标签边缘有 16 像素的边距。
提前谢谢你。
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell uicollectionviewlayout