2012-05-29 121 views
5

我編程創建了一個UISCrollView,但我看不到滾動條/指標。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]; 

此代碼我把它添加到其再裝上另一大的滾動型的視圖..有誰知道爲什麼是這樣的情況?也爲了簡化我已經每個拉布勒包含文本減少到的話,但在程序我有文本足以滾動

謝謝..

+2

如果contentSize屬性設置正確,滾動條應該在滾動時可見。但我不認爲將scrollview作爲另一個滾動視圖的子視圖是一個好主意。 –

+0

這是爲什麼?我有一個主scrollView和一個SubScrollView,我需要用於我的iPad應用程序。有沒有其他方法可以實現這一點? – CodeGeek123

+0

也設置內容不正確的工作在我的情況下 – CodeGeek123

回答

2

對於滾動視圖中滾動,內容大小爲滾動視圖必須大於其界限。請加入這行,然後檢查:

contentScrollView.contentSize=CGSizeMake(320, 250); 

,並設定了contentScrollView.bouncesYES和刪除行contentScrollView.showsVerticalScrollIndicator=YES因爲你已經先在值設置爲NO,然後YES

這應該做的工作。

+4

你可能意味着他應該刪除'contentScrollView.showsVerticalScrollIndicator = NO'?他希望看到該指標... –

+0

謝謝*她:@ – CodeGeek123

+0

contentScrollView.showsVerticalScrollIndicator = NO的值被覆蓋爲YES,因此它不能成爲無法看到滾動條的原因。 – Singh

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