collectionViewで表示するテキストによって高さを変えようとしました。調べながら以下のコードに行き着いたのですが、if文内のframeでExpression type '@lvalue CGRect' is ambiguous without more contextというエラーが出てしまいます。
Swift
1func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 2 3 if let messageText = messages?[indexPath.item].text { 4 let size = CGSize(width: view.frame.width,height: 1000) 5 let options = NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin) 6 let attribute = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18)] 7 8 let estimatedFrame = NSString(string: messageText).boundingRect(with: size, options: options, attributes: attribute, context: nil) 9 //下のframe 10 return CGSize(view.frame.width, estimatedFrame) 11 12 } 13 return CGSize(width: view.frame.width, height: 100) 14 }
回答1件
あなたの回答
tips
プレビュー