UIScrollView 看不到 ScrollBars/Indicators.

时间:2022-12-31
本文介绍了UIScrollView 看不到 ScrollBars/Indicators.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

谢谢..

推荐答案

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

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);

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

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.

这应该可以完成工作.

这篇关于UIScrollView 看不到 ScrollBars/Indicators.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:scrollToTop 在 iPhone 上不工作,但在 iPad 上工作 下一篇:UIScrollView 边界尚未在“viewDidLoad"中调整大小.

相关文章

最新文章