【问题标题】:clipping an image objective-c裁剪图像objective-c
【发布时间】:2011-04-23 13:37:37
【问题描述】:

我创建了一个图像网格。 这些图像的框架是正方形的(CGRects)。 不幸的是,图像不成比例地填充了正方形。 但我想“裁剪”或“掩盖”给定的图像。这意味着我的框架将仅显示图像的一部分,但按比例正确。我尝试了 UIImageView 的 contentModes 但没有运气。

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

}

【问题讨论】:

    标签: objective-c uiimage mask crop


    【解决方案1】:

    你确定 contentMode 不会做你想做的事吗?如果我理解正确,UIViewContentModeScaleAspectFill 将完全按照您的描述行事。

    【讨论】:

    • 嗯,检查 imageViews 的 clipsToBounds 属性是否设置为 YES。
    猜你喜欢
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2012-11-26
    • 2012-11-17
    • 1970-01-01
    • 2017-08-04
    • 2022-12-19
    • 2017-05-22
    相关资源
    最近更新 更多