create UIImageView with portion of image file

前端 未结 1 1282
鱼传尺愫
鱼传尺愫 2020-12-30 15:48

I\'m subclassing UIImageView to create a tile-based application. Essentially, I am taking a single image file and breaking it up into pieces, and then assignin

相关标签:
1条回答
  • 2020-12-30 16:28

    Here we go:

    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);
    
    0 讨论(0)
提交回复
热议问题