我從數據試圖加載圖像:的UIImageView忽略內容模式形式圖像數據
NSError *error ;
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
NSData *encryptedData = [NSData dataWithContentsOfFile:imagePath];
NSData *decryptedData = [RNDecryptor decryptData:encryptedData
withPassword:PASSWORD
error:&error];
UIImage *image = [UIImage imageWithData:decryptedData];
//adding image
UIImageView *movingImageView = [[UIImageView alloc]initWithImage:image];
[movingImageView setContentMode:UIViewContentModeScaleAspectFit];
[self.scrollView addSubview:movingImageView];
現在movingImageView
忽略了內容模式!如果我宣佈其框架,它將被修復!但問題是我的數據是不同的圖像與不同的width
大小。任何解決方案
編輯: 實測值的溶液:
movingImageView.frame = CGRectMake(0, 0, image.size.width/2, image.size.height/2);
'initWithImage:'將視圖框設置爲圖像的大小,所有'contentMode'值都會有相同的效果。您需要分別爲「contentMode」設置框架以更改圖像的顯示方式。 – Mats