简体   繁体   English

UIImageView调整大小

[英]UIImageView resize

I've made a UIImageView with the correct size in the interface builder and connected the outlet up in the class file. 我在界面构建器中创建了一个具有正确大小的UIImageView,并在类文件中将插座连接起来。 How can I stop a large jpg from filling the entire screen? 如何阻止大型jpg填满整个屏幕? I want the image to resize to fit in the frame I made in IB. 我希望图像调整大小以适应我在IB中制作的帧。

- (void)viewDidLoad {
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"wine" ofType:@"jpg"];  
    NSData* data = [NSData dataWithContentsOfFile:filePath];  
    if(data){
        photo.image= [[UIImage alloc] initWithData:data];
    }
    [super viewDidLoad];
}

THANKS. 谢谢。

In Interface Builder, select your UIImageView and open the Attributes Inspector (Command-1). 在Interface Builder中,选择您的UIImageView并打开Attributes Inspector(Command-1)。 Change the View Mode to "Aspect Fit". 将视图模式更改为“Aspect Fit”。

If you want to do this in code, set the contentMode of your UIImageView to UIViewContentModeScaleAspectFit. 如果要在代码中执行此操作,请将UIImageView的contentMode设置为UIViewContentModeScaleAspectFit。

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

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