我有一个UIImageView,目标是通过给它一个高度或宽度按比例缩小它.
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
//Add image view
[self.view addSubview:imageView];
//set contentMode to scale aspect to fit
imageView.contentMode = UIViewContentModeScaleAspectFit;
//change width of frame
CGRect frame = imageView.frame;
frame.size.width = 100;
imageView.frame = frame;
Run Code Online (Sandbox Code Playgroud)
图像确实调整了大小但位置不在左上角.缩放image/imageView的最佳方法是什么?如何更正位置?
如何获得UIImageView的比例因子,其模式是AspectFit?
也就是说,我有一个带有AspectFit模式的UIImageView.图像(方形)缩放到我的UIImageView框架,这很好.
如果我想获得所使用的量表(例如0.78或其他),我该如何直接得到它?
我不想比较说父视图宽度与UIImageView宽度,因为计算必须考虑方向,注意我正在将方形图像缩放为矩形视图.因此,为什么我会直接查询UIImageView以找出答案.
编辑:我需要它也适用于iPhone或iPad部署.