0

我正在尝试在填充真实数据之前创建示例库。

    float xAxis = 0;
    float mostHeight = self.galleryView.bounds.size.height;
    for (int i = 0; i < 5; i++) {

        //getImage from url
        UIImage* myImage = [UIImage imageWithData: 
                            [NSData dataWithContentsOfURL: 
                             [NSURL URLWithString: @"http://4.bp.blogspot.com/-M9k3fhlUwmE/TdYgxL97xMI/AAAAAAAAAY8/_r45zbAm1p0/s1600/CARTOON_Cat-full.jpg"]]];
        myImage = [[MyMath sharedMySingleton] imageWithImage:myImage convertToSize:CGSizeMake(mostHeight - 10, mostHeight - 10)];
        //set image
        UIImageView *rview= [[UIImageView alloc] initWithImage:myImage];
        /*adding the view to your scrollview*/
        [self.galleryView addSubview:rview];
        xAxis += myImage.size.width + 20;
    }
    //set scrolling area
    self.galleryView.contentSize = CGSizeMake(xAxis, mostHeight);

galleryView 是来自 xib 的 UIScrollView。在这里,我试图将 5 张相同的图片填充到图库,但它只填充了一张和之后的空格(因为 xAxis 编号)。我做错了什么?

PS我是iPhone sdk的新手,所以不要评判我

4

2 回答 2

1

你从来没有为UIImageView. 您需要将( ) 的x坐标偏移图像视图的宽度 + 填充。originframeframe.origin.x

于 2012-06-29T11:55:40.207 回答
0

您忘记使用 xAxis 的 x-Offset 为您的 imageView 设置框架。

于 2012-06-29T11:55:46.000 回答