2010-10-10 112 views
1

我創建了一個圖像網格。 這些圖像的幀是正方形(CGRects)。不幸的是,這些圖像不成比例地適合廣場。 但我想「裁剪」或「掩蓋」給定的圖像。這意味着我的框架將只顯示圖像的一部分,但按比例正確。我嘗試了UIImageView的contentModes,但沒有運氣。裁剪圖像objective-c

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

你確定contentMode不會做你想要的嗎?如果我理解正確,UIViewContentModeScaleAspectFill將完全按照您的描述進行。

+0

試過,但圖像/幀只是相互重疊... – algro 2010-10-11 08:41:52

+0

嗯,檢查imageViews的「clipsToBounds」屬性設置爲YES。 – zem 2010-10-11 08:49:28