我有一個鏈接到一個JSON字符串(「身體」)我的收藏查看小區內這就是一個UITextView,我要和AFNetworking解析內的所有內容。該字符串中的文本不同(我的每個「帖子」都有不同的信息)。我希望我的UITextView以使所有的文本顯示了基於我的字符串裏面的內容擴展。擴展UITextView的高度,使得它適合一個JSON字符串(iOS7)
集合視圖細胞
@property (weak, nonatomic, readonly) IBOutlet UITextView *body;
視圖控制器:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";
PostCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
NSDictionary *newPostDictionary = [self.singlePost objectAtIndex:indexPath.row];
cell.body.text = [newPostDictionary objectForKey:@"caption"];
NSLog(@"@");
return cell;
}
我嘗試添加我的視圖控制器這裏面的代碼但什麼也沒做。
- (CGFloat)textViewHeightForAttributedText: (NSAttributedString*)text andWidth: (CGFloat)width {
UITextView *calculationView = [[UITextView alloc] init];
[calculationView setAttributedText:text];
CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
return size.height;
}
謝謝。
根據問題,他希望的UITextView到程度,而不是內容萎縮。 –
他想調整的UITextView,這個他獲得文本的大小,可以改變TextView的高度。 –