我以编程方式创建了一个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];
这段代码我把它添加到一个视图,它再次附加到另一个更大的scrollview ..有谁知道为什么会这样?同样为了简单起见,我将每个标签包含的文本缩小为单词,但在程序中我有足够的文字滚动
谢谢..
答案 0 :(得分:2)
要滚动滚动视图,滚动视图的内容大小必须大于其边界。请添加此行,然后检查:
contentScrollView.contentSize=CGSizeMake(320, 250);
并将contentScrollView.bounces
设置为YES
并删除第contentScrollView.showsVerticalScrollIndicator=YES
行,因为您首先将值设置为NO
,然后设置为YES
。
这应该可以胜任。
答案 1 :(得分:0)
contentScrollView.showsHorizontalScrollIndicator = YES;
contentScrollView.showsVerticalScrollIndicator = YES;