I'm using UIScrollView
in which I have placed a UIImageView
and a UITextView
. I make the UIScrollView
to scroll both the images and text and it works fine, but my UITextView
contains dynamic text (i.e number of lines is different for each time). So I can't find the way to assign contentSize of UITextView
. Is there any way to do this?
Asked
Active
Viewed 1,313 times
0

objc-obsessive
- 825
- 1
- 12
- 18

varth_FD
- 137
- 1
- 2
- 12
2 Answers
0
calculate the text width and define your text view width using below code
+(float) calculateHeightOfTextFromWidth:(NSString *) text: (UIFont *)withFont: (float)width
:(UILineBreakMode)lineBreakMode
{
[text retain];
[withFont retain];
CGSize suggestedSize = [text sizeWithFont:withFont constrainedToSize:CGSizeMake(215, 1000) lineBreakMode:lineBreakMode];
[text release];
[withFont release];
return suggestedSize.height;
}
and use when you want to display dynamic text as
float titleHeight;
titleHeight = [Your view controllre ViewController calculateHeightOfTextFromWidth:[NSString stringWithFormat:@"%@",[dict objectForKey:@"title"]] :[UIFont systemFontOfSize:14]:300 :UILineBreakModeTailTruncation];
give this titleHeight to your textview or do calculation dividation using titleheight ,you can get the number of lines
If you get problem then reply