UIImageView を比例的に拡大縮小するにはどうすればいいですか? 質問する

UIImageView を比例的に拡大縮小するにはどうすればいいですか? 質問する

UIImageView があり、高さまたは幅を指定して比例して縮小することが目的です。

UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 

//Add image view
[self.view addSubview:imageView];   

//set contentMode to scale aspect to fit
imageView.contentMode = UIViewContentModeScaleAspectFit;

//change width of frame
CGRect frame = imageView.frame;
frame.size.width = 100;
imageView.frame = frame;

画像のサイズは変更されましたが、位置が左上にありません。image/imageView をスケーリングするための最適な方法と、位置を修正するにはどうすればよいですか?

ベストアンサー1

ドキュメントを見つけたら簡単に修正できました!

 imageView.contentMode = .scaleAspectFit

おすすめ記事