如何从显示的大小(给定内容模式)中检索 imageView
大小的图像,而不是根据本机属性检索图像?
码:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WID, WID)];
imageView.center = CGPointMake(point.x, point.y + Y_OFFSET);
imageView.image = [UIImage imageNamed:@"img"];
imageView.contentMode = UIViewContentModeScaleAspectFit;
1 回答
您必须再次绘制图像然后保存它 .
上面的代码在框架中绘制图像,拉伸到边界 . 如果你想要绘制它的任何其他模式,你必须自己计算它们并将所需的东西放在“绘制图像”代码行中 .
例如,对于纵横拟合,请查看此算法:
只需传入
imageView.image.size
作为inSize
和imageView.bounds
作为maxRect .资料来源:http://iphonedevsdk.com/forum/iphone-sdk-development-advanced-discussion/15001-aspect-fit-algorithm.html