如何在tableviewcell中调整uiimageview的大小适合?

时间:2016-05-23 10:26:51

标签: objective-c uitableview uiimageview

我想将stage.addEventListener(MouseEvent.CLICK, _onStageMouseDown); function _onStageMouseDown(e:MouseEvent):void { trace(e.localX); trace(e.stageX); } //output 的大小调整为UIImageView的确切图像大小,而不会增加aspectfit模式带来的额外空间。

另外,如何调整大小以便在aspectfitmode中显示图像时不会出现问题?

2 个答案:

答案 0 :(得分:0)

UIImage img = [UIImage imageNamed:@"ABC.jpg"];
[imageView setImage:img];
imageView.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y,
                             img.size.width, img.size.height);

答案 1 :(得分:0)

您应该将UIImageView的高度约束作为IBOutLet属性,然后计算UIImage的宽高比缩放高度。基于此设置约束常数。

float ratio = SCREEN_WIDTH / width;
float scaledHeight = height * ratio;
//float scaledWidth = width * ratio; uncomment if required

//Should not exceed the Screen size to make the image visible at a time without scrolling.
if (scaledHeight > SCREEN_HEIGHT) {
scaledHeight = SCREEN_HEIGHT;
}

cell.imageHeightConstraint.constant = scaledHeight;