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

Blu*_*hin 8 iphone cocoa-touch

我想在iPhone应用程序中显示图像,但我使用的图像太大了.我想缩放它以适应iPhone屏幕,我找不到任何类来处理它.

Max*_*art 20

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

要获得iPhone屏幕的框架,您可以使用

CGRect frame = [[UIScreen mainScreen] bounds];
Run Code Online (Sandbox Code Playgroud)


Ben*_*ieb 17

在Interface Builder中,选择您的UIImageView.从"工具"菜单中,选择"属性检查器".在"图像视图属性"面板中,从"模式"弹出窗口中选择"缩放到填充".这应该缩放你的图像以适应.

  • 得到它 !imageView.contentMode = UIViewContentModeScaleAspectFit; (9认同)