【发布时间】:2014-04-25 08:03:03
【问题描述】:
我正在为 UICollectionView 构建一种状态项。我的问题是当我想向状态区域添加一些文本时,我无法自动调整为新文本的大小。我开启了自动布局,并且尝试了在 stacky 上找到的各种东西。
我认为最接近正确的是:
-(UICollectionViewCell *) collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
StatusItemModel *statusModel = [self.items objectAtIndex[indexPath indexPosition:0]];
StatusItemEventCell *statusCell = [collectionView dequeueResusableCellwithReuseIdentifier: @"EventStatusItem" forIndexPath:indexPath];
statusCell.statusTitleLabel.text = [statusModel.statusDetails valueForKey:@"title"];
statusCell.statusContentTextView.text = [statuaModel.statusDetails valueForKey:@"content"];
[statusCell layoutIfNeeded];
return statusCell;
}
// After which I believe we have to do some magic in this but what?
- (CGSize) collectionView:(UiCollectionView *) collectionView layout:(UICollectionViewLayout *) collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
// How do I get the size of the textview statusContentTextView.text?
// With that I'll be able to figure out what needs to be returned.
return CGSizeMake(299.f, 200.f);
}
自动布局设置了单元格中所有元素的约束。我什至玩过内在大小和占位符,但现在还是运气。请有人指出我正确的方向。
【问题讨论】:
-
看看这个。希望对你有帮助stackoverflow.com/questions/7754851/…
标签: ios objective-c autolayout