我有一個UICollectionView
。 UICollectionViewCell
包含UITextView
。我想動態更改UITextView
的框架。我使用下面的代碼。問題在於有時候這是有效的,其他時候不會,框架也不會改變。我不確定問題是什麼。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("message_cell" , forIndexPath: indexPath) as! DisplayMessageCollectionViewCell
if let messageText = "testing" {
let size = CGSizeMake(250, 1000)
let options = NSStringDrawingOptions.UsesFontLeading.union(.UsesLineFragmentOrigin)
let estimatedFrame = NSString(string: messageText).boundingRectWithSize(size, options: options, attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14)], context: nil)
if let user_id = NSUserDefaults.standardUserDefaults().stringForKey("userId") {
if (user_id == "testing") {
cell.messageTextView.frame = CGRectMake(view.frame.width - estimatedFrame.width - 16 - 8, 0, estimatedFrame.width + 16, estimatedFrame.height + 20)
}
else {
cell.messageTextView.frame = CGRectMake(48 + 3, 0, estimatedFrame.width + 15, estimatedFrame.height + 20)
}
}
}
return cell
}
目前,做的所有單元格的大小250×1000,即使他們的幀進行復位? – Lahav
不,他們不.. – Alk
所以重置框架沒有問題? – Lahav