2010-05-31 88 views
0

我想创建一个水平的UIScrollView与其中的几个图像。用户应该能够在所有图像之间水平滚动。如果他按住手指,则应停止滚动。UIScrollView - > UIView - > UIImageView

我虽然有关使

  • 的UIScrollView(320×122像素)
  • 的UIView的内容+真正的大宽度
  • 的UIImageView对于个体图像

这里是我的代码:

headScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 122)]; 
[self.view addSubview:headScrollView]; 
// Dafür einen contentView programmatisch festlegen 
headContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, headScrollView.frame.size.height)]; 
[headContentView setBackgroundColor:[UIColor lightGrayColor]]; 
[headScrollView addSubview:headContentView]; 
[headScrollView setContentSize:headContentView.frame.size]; 

headImageView = [[UIImageView alloc] init]; 
NSMutableArray *elements = [appDelegate getElements]; 
for (int i = 0; i < [elements count]; i++) { 
    headImageView.image = [UIImage imageNamed:[[elements objectAtIndex:i] nameOfElement]]; 
    [headContentView addSubview:headImageView]; 
} 

但它不工作。没有图片有:-(当我做了我的NSLog得到图像的3名,所以它应该工作...

任何想法?

谢谢!

回答

0

使用的是单实例UIImageView的设置在设置图像的循环中,实际上是在更改同一个UIImageView的图像,并且您在这里不是headContentView 1.设置滚动视图的内容大小以适合3个图像视图 2.只需添加不同的实例UIImageView通过在滚动时更改框架。

您可以参考样本'PageControl'

Regards, Deepa