所以我试图将图像从相机加载到图像视图中。我已经完成了,但是图像纵横比发生了变化。
我尝试为 imageview 设置内容模式,但没有效果。这是我的做法:
UIImage *picture=[UIImage imageWithData:slika];
imageview = UIViewContentModeScaleAspectFit;
[imageview setImage:picture forState:UIControlStateNormal];
有任何想法吗?
所以我试图将图像从相机加载到图像视图中。我已经完成了,但是图像纵横比发生了变化。
我尝试为 imageview 设置内容模式,但没有效果。这是我的做法:
UIImage *picture=[UIImage imageWithData:slika];
imageview = UIViewContentModeScaleAspectFit;
[imageview setImage:picture forState:UIControlStateNormal];
有任何想法吗?
图像视图是您自己的视图吗?或者它是,例如,单元格的默认 imageView?
你应该这样写:
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.image = [UIImage imageNamed:picture];
或者
[imageView setImage:picture];
UIImageView没有方法[imageview setImage:picture forState:UIControlStateNormal];,它仅适用于 UIButton(可能适用于其他一些 UIControl,但 UIImageView 不是 UIControl 的子类 - 它是 UIView 的直接子类)。但是按钮不会缩放保留纵横比的图像。