0

UIView にスクロールビューを追加して、ラベル、テキストビュー、画像を配置しようとしていますが、スクロール バーが表示されず、スクロールできません。

    //faux view
UIView* fauxView = [[[UIView alloc] initWithFrame: CGRectMake(10, 10, 200, 200)]autorelease] ;
[self.bgView addSubview: fauxView];

//the new panel
self.bigPanelView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.frame.size.width, self.bgView.frame.size.height)]autorelease];
self.bigPanelView.center = CGPointMake( self.bgView.frame.size.width/2, self.bgView.frame.size.height/2);
self.bigPanelView.backgroundColor = self.initialBackgroundColor;


UIScrollView * scroll = [[UIScrollView alloc] initWithFrame:self.bigPanelView.bounds];
[scroll setContentSize:CGSizeMake(200, 200)];
[self.bigPanelView addSubview:scroll];
scroll.showsVerticalScrollIndicator = YES;



// add label

UILabel *lblTitle = [[[UILabel alloc] initWithFrame:CGRectMake(0, 25, self.bgView.frame.size.width, 46)]autorelease]; 
// If I change the 25 to 235 the label will come under the screen but still I cannot    scroll.
lblTitle.textAlignment = NSTextAlignmentCenter; // Align the label text in the center
lblTitle.backgroundColor = [UIColor clearColor];
lblTitle.text = self.initialTitle;
lblTitle.textColor = self.initialTitleColor;
lblTitle.font = [UIFont systemFontOfSize:31];
[scroll addSubview: lblTitle]; 
4

2 に答える 2

3

スクロールcontentSizeビューをビューより大きくする必要があります。

[scroll setContentSize:CGSizeMake(200, 200)];

次のようなものである必要があります:

[scroll setContentSize:CGSizeMake(400, 400)];

もちろん、スクロールビューを配置するコンテンツのサイズを設定してください。そうすれば、必要な場合にのみスクロールします。

于 2013-03-15T12:58:09.253 に答える
2

スクロールの場合-scrollViewcontentSizeは、scrollViewフレームよりも大きくする必要があります。

于 2013-03-15T12:57:27.397 に答える