Is it possible to tile images in a UIScrollView without having to manually create all the tiles?

前端 未结 5 1588
清歌不尽
清歌不尽 2020-12-23 18:20

In the iPhone sample code \"PhotoScroller\" from WWDC 2010, they show how to do a pretty good mimmic of the Photos app with scrolling, zooming, and paging of images. They al

5条回答
  •  天命终不由人
    2020-12-23 18:31

    Here goes the piece of code for tiled image generation:

    In PhotoScroller source code replace tileForScale: row:col: with the following:

    inImage - Image that you want to create tiles

    - (UIImage *)tileForScale: (float)scale row: (int)row column: (int)col size: (CGSize)tileSize image: (UIImage*)inImage
    {
        CGRect subRect = CGRectMake(col*tileSize.width, row * tileSize.height, tileSize.width, tileSize.height);
        CGImageRef tiledImage = CGImageCreateWithImageInRect([inImage CGImage], subRect);
        UIImage *tileImage = [UIImage imageWithCGImage: tiledImage];
        return tileImage;
    }
    

    Regards, Deepa

提交回复
热议问题