I have a scrollView which consists of 3 textViews, buttons and labels in a detailView. i am using 3 text view because i need different fonts for my view title, date and descript
You need to adjust the frames of the text views to match their respective contentSizes (see the top answer here: How do I size a UITextView to its content? on how to do that, uses the contentSize property of the textview), then you adjust the contentSize of the scrollView based on the frames of all the controls.
Assuming your textviews are placed consecutively vertically (just adjust the code if there is spacing, etc.):
// (first adjust each text view's frame per the linked answer)
...
// then adjust the frames of the content
CGRect topTextViewFrame = topTextView.frame;
CGRect middleTextViewFrame = middleTextView.frame;
middleTextViewFrame.origin.y = topTextViewFrame.origin.y + topTextViewFrame.size.height;
middleTextView.frame = middleTextViewFrame;
CGRect bottomTextViewFrame = bottomTextView.frame;
bottomTextViewFrame.origin.y = middleTextViewFrame.origin.y + middleTextViewFrame.size.height;
// then adjust your other controls based on these frames, for example:
CGRect myButtonFrame = myButton.frame;
myButtonFrame.origin.y = bottomTextViewFrame.origin.y + bottomTextViewFrame.size.height;
// finally adjust the contentSize of the scrollview assuming the button is the bottom element
CGSize csize = myScrollView.contentSize;
csize.height = myButtonFrame.origin.y + myButtonFrame.size.height;
myScrollView.contentSize = csize;
You could set the size of the frame to be dependent on the character length by setting the frame at the onset to be:
CGRectMake (0.0, 0.0, [yourString count]*10, 30.0);
This is what I did when I had a UIPopover come up with a variable name.