0

I am a newcomer to the realm of iOS development.

I am trying to get the UIScrollView control to work and ran across the following question:

steps for creating UIScrollView with Interface Builder

I followed the steps outlined in the answer for this question and everything works as I want. However, this appears to create a statically-sized view that is scrolled. What I am really after is a dynamically sized view that may or may not be scrolled. For example, instead of the view with buttons, I put a single label for which I set the text and number of lines in the viewDidLoad method. The view that contains the label is set to a static size so the scroll viewer does not attempt to scroll and the content of the label spills off of the page.

What am I missing?

Community
  • 1
  • 1
Jason Richmeier
  • 1,595
  • 3
  • 19
  • 38
  • One way to resize the content view outlet automatically is to implement its [sizeThatFits:](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/sizeThatFits:), you might need to call [sizeToFit](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/sizeToFit) manually as well. – A-Live Jun 18 '13 at 17:51
  • Please post what you have tried up till now, your question is not self explanatory – Sarim Sidd Jun 18 '13 at 17:52
  • The answer that was posted on the following question is what I was looking for: http://stackoverflow.com/questions/13317829/uiview-inside-uiscrollview-bounces-back – Jason Richmeier Jun 19 '13 at 15:03

3 Answers3

0

you need to set te content size of the scroll

CGPoint controlsCenter = ViewBottom.center;
if(Pointsvalue > 5)
{
controlsCenter.y += txtFldFrame1.frame.origin.y+20;
ViewBottom.center = controlsCenter;

[ScrollLag addSubview:ViewBottom];
}

[ScrollLag setContentSize:(CGSizeMake(0, controlsCenter.y+100))];

make sure your label height changes on entering text.......

Agent Chocks.
  • 1,312
  • 8
  • 19
0

The URL in my comment to the original question provides a solution to the issue I raised.

Jason Richmeier
  • 1,595
  • 3
  • 19
  • 38
0

I have a dynamically sized UIScrollView in a project I am working on right now. This is what I did:

self.myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 250, 748)];
[self.myScrollView setBackgroundColor:[UIColor blackColor]];
int heightCounter = 10;

UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom];
newButton.frame = CGRectMake(10, heightCounter, 200, 40);
[newButton setBackgroundColor:[UIColor clearColor]];
[newButton addTarget:self action:@selector(someMethod:) forControlEvents:UIControlEventTouchUpInside];
[newButton setTitle:@"ButtonTitle" forState:UIControlStateNormal];
[newButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.myScrollView addSubview:newButton];
heightCounter += 50;

// add additional items to the myScrollView and remember to increase the heightCounter

self.myScrollView.contentSize = CGSizeMake(250, heightCounter);
self.myScrollView.scrollEnabled = YES;
[self.view addSubview:self.myScrollView];
sangony
  • 11,636
  • 4
  • 39
  • 55