Correct image resize adjustment for scaling up images
This commit is contained in:
parent
f7dec4cf23
commit
a90930c7f9
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue