2
나는 UITextView
을 포함하는 Cell
의 UICollectionView
을 가지고 있습니다. TextView의 높이에 따라 셀의 크기가 달라지기를 원합니다 (스크롤이 필요없고 모든 텍스트가 항상 표시되도록). 나는 이것을 시도하고있다 :컬렉션 셀 크기보기 UITextView에 따라 달라짐
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
if (indexPath.row < myComments!.count) {
if let messageText = myComments![indexPath.row].text {
let size = CGSizeMake(self.view.frame.width/2, 100)
let options = NSStringDrawingOptions.UsesFontLeading.union(.UsesLineFragmentOrigin)
let estimatedFrame = NSString(string: messageText).boundingRectWithSize(size, options: options, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14)], context: nil)
return CGSizeMake(view.frame.width, estimatedFrame.height + 50)
}
}
return CGSizeMake(view.frame.width, 100)
}
그러나 이것은 실제로 작동하지 않는다. 때로는 높이가 너무 길고 때로는 너무 작아서 스크롤해야합니다.