UIScrollView中无法看到滚动条/指标。(UIScrollView cannot see S

2019-06-24 22:42发布

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

此代码我把它添加到其再装上另一大的滚动型的视图..有谁知道为什么是这样的情况? 同样为了简单起见,我已减少每个拉布勒包含的话,但在程序中的文本我有文本足以滚动

谢谢..

Answer 1:

对于滚动视图滚动,滚动视图内容大小必须比其边界更大。 请加入这行,然后检查:

contentScrollView.contentSize=CGSizeMake(320, 250);

并且还设置contentScrollView.bouncesYES和删除行contentScrollView.showsVerticalScrollIndicator=YES作为您已先设定的值,以NO然后YES

这应该做的工作。



Answer 2:

contentScrollView.showsHorizontalScrollIndicator = YES;
contentScrollView.showsVerticalScrollIndicator = YES;


文章来源: UIScrollView cannot see ScrollBars/Indicators.