It depends on the type of content you want to add dynamically. So, let's say you have big text data to display, then use a UITextView and, since it is a subclass of UIScrollView, you can get setContentSize TextView when assigning text content. Based on this, you can set the overall size of the UIScrollView.
float yPoint = 0.0f; UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, yPoint, 320.0f, 400.0f)]; UITextView *calculatorTextView = [[UITextView alloc] init]; calculatorTextView.text = @"My looong content text ..... this has a dynamic content"; ` [calculatorTextView sizeToFit]; yPoint = yPoint + calculatorTextView.contentSize.height;
// Now you know the height of the text and its end. Thus, you can create a shortcut or other TextView and display your text there. You can add these components as a subview in scrollview.
UITextView *myDisplayContent = [[UITextView alloc] initWithFrame:CGRectMake(0.0f, yPoint, 300.f, calculatorTextView.contentSize.height)]; myDisplayContent.text = @"My lengthy text ...."; [myScrollView addSubview:myDisplayContent];
// Finally, set the content size of "myScrollView" to the total length of the display area.
[myScrollView setContentSize:yPoint + heightOfLastComponent]
This works for me.
chathuram
source share