我有一个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