4

インターフェイスビルダーで正しいサイズの UIImageView を作成し、クラスファイルでアウトレットを接続しました。大きな jpg が画面全体に表示されないようにするにはどうすればよいですか? 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];
}

ありがとう。

4

1 に答える 1

12

Interface Builder で、UIImageView を選択し、属性インスペクター (Command-1) を開きます。ビュー モードを「アスペクト フィット」に変更します。

コードでこれを行う場合は、UIImageView の contentMode を UIViewContentModeScaleAspectFit に設定します。

于 2009-09-06T21:53:49.123 に答える