algro
algro

Reputation: 637

clipping an image objective-c

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];

}

Upvotes: 1

Views: 1078

Answers (1)

zem
zem

Reputation: 1257

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

Upvotes: 1

Related Questions