gpt4 book ai didi

objective-c - 图像被拉伸(stretch)

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:51:33 26 4
gpt4 key购买 nike

我有一张图片(从我们的服务器获取),我想将它放入 UIImageView 中。图片为 373x500。 UIImageView 是 443x290 并且 View 正在拉伸(stretch)它。

UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 
0,
500,
300)];

myImageView.image = [UIImage imageWithData:photoData];
myImageView.backgroundColor = [UIColor viewBackgroundColor];
myImageView.contentMode = UIViewContentModeScaleAspectFit;

NSLog(@"myImageView.image.size: %@", NSStringFromCGSize(myImageView.image.size));
NSLog(@"myImageView.frame.size: %@", NSStringFromCGSize(myImageView.frame.size));

[wrapperView addSubview:myImageView];

日志读取:

2012-05-09 11:32:52.621[89145:1a303] myImageView.image.size: {373, 500}
2012-05-09 11:32:52.622[89145:1a303] myImageView.frame.size: {443, 290}

看起来像:

enter image description here

“UIViewContentModeScaleAspectFit”不应该告诉它保持比例而不拉伸(stretch)图像吗?

最佳答案

您还应该在 View 上设置 clipsToBounds = YES

关于objective-c - 图像被拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10520404/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com