[英]How to resize UIImageView based on UIImage's size/ratio in Swift 3?
[英]UIImage imageWithData how to find image size and resize ratio
我有两个需要彼此相对的UIImage,但是我不知道如何计算已设置为我在Base64数据中接收的图像的实际大小的UIImage大小。
目前,我是在不计算原始imageview大小变化的情况下执行此操作的,当前profileImageView比它需要的要大得多,因为它不是动态的。
if ([recivedRquestType isEqualToString:@"FaceBlank"]) {
FaceBlankImage = [UIImage imageWithData:data];
[imageView removeFromSuperview];
imageView = nil;
imageView = [[UIImageView alloc] initWithImage:FaceBlankImage];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.frame = CGRectMake(0.0, 70.0, ScreenWidth, (ScreenHeight/2)-75);
[self.view addSubview:imageView];
// call profile
[engineRequests GetImageK:currProfile RequestType:@"Profile" NavController:self.navigationController];
} else if ([recivedRquestType isEqualToString:@"Profile"]) {
profileImage = [UIImage imageWithData:data];
[profileImageView removeFromSuperview];
profileImageView = nil;
profileImageView = [[UIImageView alloc] initWithImage:profileImage];
profileImageView.contentMode = UIViewContentModeScaleAspectFit;
profileImageView.frame = CGRectMake(0.0, (ScreenHeight/2)-10, ScreenWidth/2, 50.0);
[self.view addSubview:profileImageView];
}
这是通过将所有内容放置在正确的位置来实现的,只是图像调整比例与profileImage不同,我需要使它们相同。
UIImage
具有size
属性,它是CGSize
结构。 那应该给你图像本身的宽度和高度。
它还有两个其他属性,分别称为scale
和resizingMode
,您可能也想检查一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.