5

I programatically created a UISCrollView but i cant see the scrollbars/indicators.

UIScrollView * contentScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(760, 70, 205, 320)];
contentScrollView.delegate = self;
contentScrollView.scrollEnabled = YES;
contentScrollView.pagingEnabled = YES;
contentScrollView.userInteractionEnabled=YES;
contentScrollView.scrollsToTop = YES;
contentScrollView.showsVerticalScrollIndicator = NO;
contentScrollView.showsVerticalScrollIndicator = YES;
contentScrollView.alwaysBounceVertical = NO;
contentScrollView.alwaysBounceHorizontal = NO;
contentScrollView.bounces = NO;
contentScrollView.hidden = NO;
[contentScrollView flashScrollIndicators];
UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 205, 40)];
UILabel *subtitleLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 205, 50)];
UITextView * mainContent = [[UITextView alloc]initWithFrame:CGRectMake(10, 110, 205, 230)];

[titleLable setText:@"...."];
[subtitleLable setText:@"SUbtitle"];
[mainContent setText:@"Descritpon"];
[contentScrollView addSubview:mainContent];
[contentScrollView addSubview:titleLable];
[contentScrollView addSubview:subtitleLable];

This code i add it to a view which is again attached to another bigger scrollview.. Does anyone know why this is the case? Also for simplicity i have reduced the text each lable contains to words but in the program i have the text is sufficient to scroll

Thanks..

CodeGeek123
  • 4,341
  • 8
  • 50
  • 79
  • 2
    Scrollbars should be visible while scrolling if the contentSize property is set correctly. But i don't think adding a scrollview as a subview of another scrollview is a good idea. – Rok Jarc May 29 '12 at 15:09
  • Why is that? I have a main scrollView and also a SubScrollView that i need used for my iPad app. Is there any other way to achieve this? – CodeGeek123 May 29 '12 at 15:14
  • Also set content doesnt exactly work in my case – CodeGeek123 May 29 '12 at 15:19
  • You'll have to implement some kind of mechanism to decide which touches should go to parent- and which to child-scrollview. I'm not saying it's impossible... You'll have to make sure that the behaviour will be understandable to your users. As for setting content size I really can't see why this wouldn't work in your case (if it's not bigger than scrollView's size there will be no scrolling). – Rok Jarc May 29 '12 at 15:24
  • Thanks for the explanation. I have written another question with more detail http://stackoverflow.com/questions/10802454/uiscrollview-within-scrollview-scrollbars-not-showing – CodeGeek123 May 29 '12 at 15:47

2 Answers2

2

For the scroll view to scroll, the content size for the scroll view must be greater than its bounds. Please add this line and then check:

contentScrollView.contentSize=CGSizeMake(320, 250);

and also set the contentScrollView.bounces to YES and remove the line contentScrollView.showsVerticalScrollIndicator=YES as you have first set the value to NO and then YES.

This should do the job.

Steph Sharp
  • 11,462
  • 5
  • 44
  • 81
Singh
  • 2,151
  • 3
  • 15
  • 30
  • 4
    You probably mean that he should remove `contentScrollView.showsVerticalScrollIndicator=NO`? He wants to see that indicator... – Rok Jarc May 29 '12 at 15:39
  • The value for the contentScrollView.showsVerticalScrollIndicator=NO is being overwritten to YES , so it must not be the reason for not able to see the scrollbars . – Singh May 29 '12 at 16:08
  • @CodeGeek123 please remove the line [contentScrollView flashScrollIndicators]; and then check . – Singh May 29 '12 at 16:09
0
contentScrollView.showsHorizontalScrollIndicator = YES;
contentScrollView.showsVerticalScrollIndicator = YES;
Carmen
  • 6,177
  • 1
  • 35
  • 40
Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42