问题描述
我对 UIImageView 显示图像的方式感到非常失望.
我有以下一段代码:
UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)];imgview.image = [UIImage imageNamed:@"img.JPG"];imgview.backgroundColor = [UIColor greenColor];imgview.contentMode = UIViewContentModeScaleAspectFit;[self.view addSubview:imgview];
我得到的是以下屏幕截图:
http://img26.imageshack.us/img26/3686/screenshot20130123at629.png>
[图像被拉伸到 UIImageView 的全宽,甚至没有全高]
原图:
http://img248.imageshack.us/img248/341/screenshot20130123at638.png>
设置大小必须在设置 contentMode 之后进行
[imageView setContentMode: UIViewContentModeScaleAspectFit];imageView.frame = CGRectMake(x, y, width, height);
I am really disappointed by the way UIImageView displays the image.
I have following piece of code:
UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)];
imgview.image = [UIImage imageNamed:@"img.JPG"];
imgview.backgroundColor = [UIColor greenColor];
imgview.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:imgview];
What I get is a following screenshot:
http://img26.imageshack.us/img26/3686/screenshot20130123at629.png
[image is stretched to full width of UIImageView and does not even take full height]
Original image:
http://img248.imageshack.us/img248/341/screenshot20130123at638.png
Setting the size must occur AFTER setting the contentMode
[imageView setContentMode: UIViewContentModeScaleAspectFit];
imageView.frame = CGRectMake(x, y, width, height);
这篇关于即使 contentMode = UIViewContentModeScaleAspectFit UIImageView 图像也会拉伸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!