問題描述
我以編程方式創(chuàng)建了一個(gè) UISCrollView,但我看不到滾動(dòng)條/指示器.
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];
我將這段代碼添加到一個(gè)視圖中,該視圖再次附加到另一個(gè)更大的滾動(dòng)視圖.有誰知道為什么會(huì)這樣?同樣為簡(jiǎn)單起見,我將每個(gè)標(biāo)簽包含的文本減少為單詞,但在程序中我的文本足以滾動(dòng)
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
謝謝..
推薦答案
要讓滾動(dòng)視圖滾動(dòng),滾動(dòng)視圖的內(nèi)容大小必須大于其邊界.請(qǐng)?zhí)砑哟诵腥缓髾z查:
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
設(shè)置為 YES
并刪除 contentScrollView.showsVerticalScrollIndicator=YES
行,因?yàn)槟紫葘⒅翟O(shè)置為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
.
這應(yīng)該可以完成工作.
這篇關(guān)于UIScrollView 看不到 ScrollBars/Indicators.的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!