Hi folks, does anyone know how to crop an UIImageView? I have seen this discussion in about a dozen threads but didn't find the answer yet.
I tried some implementations such as:
Initialization
Code:
self.timeBarUIImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kTimeBarSpaceFromLeft, kTimeBarSpaceFromTop, kTimeBarWidth, kTimeBarHeight)];
[self.timeBarUIImageView setImage: [UIImage imageNamed:@"TargetGameTimeBar_100.png"]];
self.timeBarUIImageView.contentMode = UIViewContentModeScaleAspectFill;
self.timeBarUIImageView.clipsToBounds = YES;
And in a method which is called by a NSTimer I'm trying to clip the UIImageView so as that the image will appear smaller every iteration, using the Code:
Loop
Code:
CGRect frame = [self.timeBarUIImageView frame];
frame.size.width -= kTimeBarDecreasingFactor;
[self.timeBarUIImageView setFrame:frame];
Doing this I can see my UIImageView becoming smaller, but not the way I desire ( I want to clip the image from right to left, soh as that in the last iterations the image displayed would be the most-left portion of the image.
I also tried to play with bounds/center but I didn't get the desired result either (the image became smaller but the final image displayed was the pixels of the center of image (instead of the left-most pixel as I expected)).
I've found resources showing how to use the Low-level API (UIGraphicsGetCurrentContext(), etc) showing the code to resize an UIImage. I also found some interesting link such as
Code Sample: Crop an image using the iPhone SDK | Hive05 software products but it didn't work well here.
Any suggestions?