Correct image resize adjustment for scaling up images

This commit is contained in:
Maurice Parker 2020-07-21 18:34:31 -05:00
parent f7dec4cf23
commit a90930c7f9
3 changed files with 11 additions and 1 deletions

View File

@ -39,7 +39,11 @@ struct IconImageView: View {
let newSize: CGSize
if imageSize.height == imageSize.width {
return imageSize
if imageSize.height >= viewSize.height {
newSize = CGSize(width: viewSize.width, height: viewSize.height)
} else {
newSize = CGSize(width: imageSize.width, height: imageSize.height)
}
} else if imageSize.height > imageSize.width {
let factor = viewSize.height / imageSize.height
let width = imageSize.width * factor

View File

@ -100,6 +100,9 @@ private extension IconView {
let imageSize = image.size
let viewSize = bounds.size
if imageSize.height == imageSize.width {
if imageSize.height >= viewSize.height {
return CGRect(x: 0.0, y: 0.0, width: viewSize.width, height: viewSize.height)
}
let offset = floor((viewSize.height - imageSize.height) / 2.0)
return CGRect(x: offset, y: offset, width: imageSize.width, height: imageSize.height)
}

View File

@ -107,6 +107,9 @@ private extension IconView {
let imageSize = image.size
let viewSize = bounds.size
if imageSize.height == imageSize.width {
if imageSize.height >= viewSize.height {
return NSMakeRect(0.0, 0.0, viewSize.width, viewSize.height)
}
let offset = floor((viewSize.height - imageSize.height) / 2.0)
return NSMakeRect(offset, offset, imageSize.width, imageSize.height)
}