简体   繁体   English

如何在iPhone UIImage或UIImageView中拉伸图像大小

[英]How to stretch the image size in iphone UIImage or UIImageView

I'd like to show an image in an iPhone app, but the image I'm using is too big. 我想在iPhone应用程序中显示图像,但是我使用的图像太大。 I'd like to scale it to fit the iPhone screen, I can't find any class to handle it. 我想缩放它以适合iPhone屏幕,找不到任何类来处理它。

UIImageView* view = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"your_image.png"]];
view.frame = CGRectMake(0, 0, width, height);

To get the frame of the iPhone screen you can use 要获取iPhone屏幕的框架,您可以使用

CGRect frame = [[UIScreen mainScreen] bounds];

In Interface Builder, select your UIImageView. 在“界面生成器”中,选择您的UIImageView。 From the Tools menu, select "Attribute Inspector". 从“工具”菜单中,选择“属性检查器”。 In the Image View Attributes palette, select "Scale to Fill" from the Mode popup. 在“图像视图属性”面板中,从“模式”弹出窗口中选择“缩放以填充”。 That should scale your image to fit. 那应该缩放您的图像以适合。

My ImageView was set in IB, and I would need to show multiple images, so set the image of imageView, instead of creating ImageView for individual image. 我的ImageView是在IB中设置的,因此我需要显示多个图像,因此设置imageView的图像,而不是为单个图像创建ImageView。

After I set the image view frame size, I am still see the same result, the image was too big, so that only part of the image was displayed on the screen. 设置图像视图框架大小后,仍然看到相同的结果,图像太大,因此屏幕上只显示了一部分图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM