ScrollView在Xcode中适应其内容?

时间:2012-11-19 06:26:50

标签: iphone xcode uiscrollview

我是Objective-C的新手,我需要根据其内容为ScrollView设置动态高度。我有一个UIView,其中有UIScrollView。我在视图上有一些UILabels,UIButtons等。现在它显示了额外的空间,我可以滚动到底部,即使我没有数据。所以如果数据完成,我需要停止滚动。我该怎么办?

[testscroll setScrollEnabled:YES];
[testscroll setContentSize:CGSizeMake(320,800)];//static size to UISCrollView


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UIButton *button=[[UIButton alloc] initWithFrame:rect];
    [button setFrame:rect];
    [button setContentMode:UIViewContentModeLeft]; 
    NSString *settitle=[NSString stringWithFormat:@"%@",item.Name]; 
    [button setTitle:settitle forState:UIControlStateNormal];
    NSString *tagValue=[NSString stringWithFormat:@"%d%d",indexPath.section+1,i]; 
    button.tag=[tagValue intValue];
    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [hlcell.contentView addSubview:button];
    [button release];

}

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

您可以根据数据调整scrollView contentSize。 就像我有一个array,我想管理滚动大小然后我做了这个。

[scrollview setContentSize:CGSizeMake(320, 100*[ary count]/4)];  

在这个数组中我有高度为100的图像,所以100*[ary count]