UIScrollView无法看到ScrollBars/Indicators.

Cod*_*123 5 iphone objective-c uiscrollview ios4 ios

我以编程方式创建了一个UISCrollView但我看不到滚动条/指示器.

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];
Run Code Online (Sandbox Code Playgroud)

这段代码我将它添加到一个视图,再次附加到另一个更大的scrollview ..有谁知道为什么会这样?同样为了简单起见,我将每个标签包含的文本缩小为单词,但在程序中我有足够的文本滚动

谢谢..

Sin*_*ngh 2

为了使滚动视图滚动,滚动视图的内容大小必须大于其边界。请添加此行,然后检查:

contentScrollView.contentSize=CGSizeMake(320, 250);
Run Code Online (Sandbox Code Playgroud)

并设置contentScrollView.bouncesYES并删除该行,contentScrollView.showsVerticalScrollIndicator=YES因为您首先将值设置为NO,然后删除该行YES

这应该可以完成工作。

  • 您可能的意思是他应该删除 `contentScrollView.showsVerticalScrollIndicator=NO`?他想看到那个指标…… (4认同)