views:

65

answers:

1

I created a Grid of Images. The frames of those images are squares-shaped(CGRects). Unfortunately the images fill-fits the square unproportionally. But I would like to "crop" or "mask" the given image. Which means my frames will show only parts of an image but proportionally correct. I tried contentModes of UIImageView but no luck.

for(int index = 0; index < (_cols*_rows) ;index++)
{
    NSValue *value = [myArray objectAtIndex:index];    
    CGRect myrect = [value CGRectValue];
    UIImageView *myImageView = [[UIImageView alloc] initWithImage:myImage];
    myImageView.frame = myrect;

    [self addSubview:myImageView];
    [myImageView release];

}
+1  A: 

Are you sure contentMode won't do what you want? If I understand you correctly, UIViewContentModeScaleAspectFill will do exactly what you describe.

zem
Tried that, but the images/frames just overlap each other...
algro
Hmm, check that the imageViews' `clipsToBounds` properties are set to YES.
zem