在UIImageView中访问调整大小的UIImage的框架
问题描述:
我使用contentMode AspectToFit在UIImageView中设置了UIImage。我如何访问调整大小显示的UIImage的框架?因为imageView.image.size.width给出图像的原始宽度,而不是调整后的宽度。在UIImageView中访问调整大小的UIImage的框架
感谢,
答
物业UIImageView
frame
将返回所显示的图像的帧。
如果你想改变框架,你应该刚刚成立的新CGRect frame
您UIImageView
例如:
UIImageView *imgView;
imgView.frame = CGRectMake(0, 0, newWidth, newHeight);
更新时间:
要计算新的大小,你可以使用下面的代码:
UIImage *img;
UIImageView *iView;
double widthRatio = img.size.width/iView.frame.size.width;
double heightRatio = img.size.height/iView.frame.size.height;
double ratio = widthRatio>heightRatio?widthRatio:heightRatio;
CGSize newImageSize;
newImageSize.width = img.size.width/ratio;
newImageSize.height = img.size.height/ratio;
我知道,我正在寻找newWidht和th e newHeight(调整大小后的图像) –
'UIImageView.frame'会给你'调整图像大小' – Nekto
nope它给出原始定义的帧。 –