【问题标题】:space between images in thumbnail for ipadipad缩略图中图像之间的空间
【发布时间】:2012-10-08 16:23:15
【问题描述】:

我用 ipad 的滚动视图创建缩略图照片,代码如下:

// load all the images from bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
    NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];


}



 - (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];

// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
    if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
    {
        CGRect frame = view.frame;
        frame.origin = CGPointMake(curXLoc, 0);
        view.frame = frame;

        curXLoc += (kScrollObjWidth);
    }
}

}

现在我在 UIScrollView 中有所有图像,它们彼此相邻,我希望每个图像之间有一些空间,就像这张图片

您能否给我一些提示,告诉我如何在这些图像之间添加空间?

提前致谢!

【问题讨论】:

    标签: objective-c ios xcode ipad uiscrollview


    【解决方案1】:

    试试这个:

    curXLoc += (kScrollObjWidth) + kDifferenceBetweenImages;
    

    并相应地定义 kDifferenceBeteweenIMages。

    【讨论】:

    • 谢谢,你知道如何在我的 uiscrollview 中的图像的 up 和 done 部分之间添加空格吗?
    【解决方案2】:

    改用 UICollectionView。更容易实现你想要的,也会更好地工作。

    它甚至还有每个单元格之间的空间属性。

    【讨论】:

      【解决方案3】:

      试试这个:

      CGRect frame = view.frame;
      frame.origin = CGPointMake(curXLoc, 0);
      frame.size.height = //put height;
      frame.size.width = //put width;
      frame.origin.y = //put y;
      view.frame = frame;
      curXLoc += (kScrollObjWidth) + 15;
      

      【讨论】:

        猜你喜欢
        • 2017-04-10
        • 1970-01-01
        • 2018-01-14
        • 2014-02-07
        • 2020-12-18
        • 2015-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多