[英]Resize UIImageView according to image size?
In IB we can use command =
to resize the UIImageView
to the original size of image. 在IB中,我们可以使用command =
将UIImageView
调整为原始图像大小。 I need to do it programmatically.I used contentMode
but it resize image itself to match UIImageView
size set in IB. 我需要以编程方式进行操作。我使用了contentMode
但是它会调整图像本身的大小以匹配IB中设置的UIImageView
大小。 Edit: I've tried 编辑:我已经尝试过
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ScanToVerifyCell" forIndexPath:indexPath];
STOScanToVerifyCell * verifyCell = (STOScanToVerifyCell *)cell;
[verifyCell.scanStatusImage setHidden:NO];
[verifyCell.scanStatusImage setImage:[UIImage imageNamed:@"point.png"]];
[verifyCell.scanStatusImage sizeToFit];
But it is not working.What i'm doing wring? 但这不起作用。我在干什么?
verifyCell.scanStatusImage.contentMode = UIViewContentModeScaleAspectFit;
verifyCell.scanStatusImage .clipsToBounds = YES;
[verifyCell.scanStatusImage sizeToFit];
Hope This Helps You......! 希望对您有帮助...!
it would be something like this: get image size by: 就像这样:通过以下方式获取图像大小:
UIImage * img = [UIImage imageNamed:@"someImage.png"];
CGSize imgSize = img.size;
calculate scale ratio on width 计算宽度比例
float ratio=yourImageView.frame.size.width/imgSize.width;
check scaled height 检查缩放高度
float scaledHeight=imgSize.height*ratio;
if(scaledHeight < yourImageView.frame.size.height)
{
//update height of your imageView frame with scaledHeight
}
SizeToFit方法将完成此工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.