This is possible.
The first case: use local images,
` UIImageView *fenxiangImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fenxiang"]];
NSLogFloat(fenxiangImageView.frameSizeWidth);
NSLogFloat(fenxiangImageView.frameSizeHeight);
[self.view addSubview:fenxiangImageView];
`
![Picture width and height][2]
As in the first case, once you know the width and height of the original image, you can scale the height in proportion to your own width.
This is possible.
The first case: use local images,
` UIImageView *fenxiangImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fenxiang"]];
NSLogFloat(fenxiangImageView.frameSizeWidth);
NSLogFloat(fenxiangImageView.frameSizeHeight);
[self.view addSubview:fenxiangImageView];
![图片描述][1] 可以看到图片宽高准确的打印出来了。然后你可以根据自己定的宽度,来等比缩放图片的高度就行了。 第二种情况:网络请求的图片,
UIImageView *urlImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"url"]]]];NSLogFloat(urlImageView.frameSizeWidth);
NSLogFloat(urlImageView.frameSizeHeight);
[self.view addSubview:urlImageView];
`
![Picture width and height][2]
As in the first case, once you know the width and height of the original image, you can scale the height in proportion to your own width.