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

对于滚动 - scrollView contentSize 应该大于 scrollView 框架。

于 2013-03-15T12:57:27.397 回答