我继承UIImageView
创建一个基于区块的应用。 从本质上讲,我以一个图像文件,并分解成片,然后分配件我的瓷砖( UIImageViews
),这样他们可以独立操作。
什么是抓住一个图像的一部分,并用它来绘制的最好方式UIImageView
? 我想到了重写drawRect
和使用CGAffineTransform
,但它好像有应该是要做到这一点,也许通过指定一个简单的方法CGRect
到UIImage
传递到UIImageView
,但我没有看到这个的API。
开始了:
UIImage* img = [UIImage imageNamed:@"myImage.jpg"];
CGRect imgFrame = CGRectMake(x, y, tileWidth, tileHeight);
CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], imgFrame);
UIImage* subImage = [UIImage imageWithCGImage: imageRef];
CGImageRelease(imageRef);