使用动态内容在Interface Builder中创建UIScrollView

时间:2013-06-18 17:36:06

标签: ios uiscrollview

我是iOS开发领域的新手。

我正在尝试让UIScrollView控件工作并运行以下问题:

steps for creating UIScrollView with Interface Builder

我按照回答中提出的步骤来解决这个问题,一切都按照我的意愿行事。但是,这似乎创建了一个滚动的静态大小的视图。我真正追求的是动态大小的视图,可以滚动也可以不滚动。例如,我放置了一个标签,而不是带按钮的视图,我在viewDidLoad方法中设置了文本和行数。包含标签的视图设置为静态大小,因此滚动查看器不会尝试滚动,标签的内容会溢出页面。

我错过了什么?

3 个答案:

答案 0 :(得分:0)

您需要设置滚动的内容大小

CGPoint controlsCenter = ViewBottom.center;
if(Pointsvalue > 5)
{
controlsCenter.y += txtFldFrame1.frame.origin.y+20;
ViewBottom.center = controlsCenter;

[ScrollLag addSubview:ViewBottom];
}

[ScrollLag setContentSize:(CGSizeMake(0, controlsCenter.y+100))];

确保输入文字时标签高度发生变化.......

答案 1 :(得分:0)

我对原始问题的评论中的网址提供了我提出的问题的解决方案。

答案 2 :(得分:0)

我正在进行的项目中有一个动态大小的UIScrollView。这就是我所做的:

self.myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 250, 748)];
[self.myScrollView setBackgroundColor:[UIColor blackColor]];
int heightCounter = 10;

UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom];
newButton.frame = CGRectMake(10, heightCounter, 200, 40);
[newButton setBackgroundColor:[UIColor clearColor]];
[newButton addTarget:self action:@selector(someMethod:) forControlEvents:UIControlEventTouchUpInside];
[newButton setTitle:@"ButtonTitle" forState:UIControlStateNormal];
[newButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.myScrollView addSubview:newButton];
heightCounter += 50;

// add additional items to the myScrollView and remember to increase the heightCounter

self.myScrollView.contentSize = CGSizeMake(250, heightCounter);
self.myScrollView.scrollEnabled = YES;
[self.view addSubview:self.myScrollView];