5

我以编程方式创建了一个 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];

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

谢谢..

4

2 回答 2

2

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

contentScrollView.contentSize=CGSizeMake(320, 250);

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

这应该可以完成这项工作。

于 2012-05-29T15:30:52.693 回答
0
contentScrollView.showsHorizontalScrollIndicator = YES;
contentScrollView.showsVerticalScrollIndicator = YES;
于 2013-04-05T07:14:38.410 回答