Aspect ratio not preserved when using fixed imageSize #62

Closed
opened 2025-10-14 15:58:18 -06:00 by navan · 0 comments
Owner

Originally created by @AndrewBennet on 6/11/2020

WhatsNewKit Environment

  • WhatsNewKit version: 1.3.3
  • Xcode version: 11.5
  • Swift version: 5
  • macOS version running Xcode: 10.15.5
  • Dependency manager (SPM, Carthage, CocoaPods, Manually): SPM (in Xcode)

What did you do?

Configured a WhatsNew.Item with an image from the iOS 13 SFSymbol library.

What did you expect to happen?

I expected the aspect ratio of the image to be preserved, especially as WhatsNewViewController.ItemsView.ImageSize.fixed is documented as /// A fixed height by keeping the aspect ratio.

What happened instead?

The image was stretched into a square.

--
Example code:

let whatsNewExample = WhatsNew(
    title: "An example of using WhatsNewKit with SFSymbols",
    items: [
        WhatsNew.Item(
            title: "Item 1",
            subtitle: "This has an SFSymbol as its image",
            image: {
                if #available(iOS 13.0, *) {
                    let config = UIImage.SymbolConfiguration(pointSize: 50)
                    return UIImage(systemName: "ant.fill", withConfiguration: config)
                } else {
                    return nil
                }
            }()
        ),
        WhatsNew.Item(
            title: "Item 2",
            subtitle: "This has an SFSymbol as its image",
            image: {
                if #available(iOS 13.0, *) {
                    let config = UIImage.SymbolConfiguration(pointSize: 50)
                    return UIImage(systemName: "tropicalstorm", withConfiguration: config)
                } else {
                    return nil
                }
            }()
        )
    ]
)

var configuration = WhatsNewViewController.Configuration()
// Use the default, preferred image size
//configuration.itemsView.imageSize = .original
window.rootViewController!.present(WhatsNewViewController(whatsNew: whatsNewExample, configuration: configuration), animated: true)

If I alter to code to set .original as the image size, the image is no longer distorted but I then do not have a nice way to ensure that the images are equal width to make them align, and so the text of each item don't have aligning leading margins:

It would seem that the resizing code in WhatsNewItemsViewController+Cell.swift, line 207, func resize(height: CGFloat) -> UIImage? doesn't do as its comment says: /// Resize UIImage to a give height by keeping the aspect ratio.

*Originally created by @AndrewBennet on 6/11/2020* ## WhatsNewKit Environment - WhatsNewKit version: 1.3.3 - Xcode version: 11.5 - Swift version: 5 - macOS version running Xcode: 10.15.5 - Dependency manager (SPM, Carthage, CocoaPods, Manually): SPM (in Xcode) ## What did you do? Configured a WhatsNew.Item with an image from the iOS 13 SFSymbol library. ## What did you expect to happen? I expected the aspect ratio of the image to be preserved, especially as `WhatsNewViewController.ItemsView.ImageSize.fixed` is documented as `/// A fixed height by keeping the aspect ratio`. ## What happened instead? The image was stretched into a square. -- Example code: ``` let whatsNewExample = WhatsNew( title: "An example of using WhatsNewKit with SFSymbols", items: [ WhatsNew.Item( title: "Item 1", subtitle: "This has an SFSymbol as its image", image: { if #available(iOS 13.0, *) { let config = UIImage.SymbolConfiguration(pointSize: 50) return UIImage(systemName: "ant.fill", withConfiguration: config) } else { return nil } }() ), WhatsNew.Item( title: "Item 2", subtitle: "This has an SFSymbol as its image", image: { if #available(iOS 13.0, *) { let config = UIImage.SymbolConfiguration(pointSize: 50) return UIImage(systemName: "tropicalstorm", withConfiguration: config) } else { return nil } }() ) ] ) var configuration = WhatsNewViewController.Configuration() // Use the default, preferred image size //configuration.itemsView.imageSize = .original window.rootViewController!.present(WhatsNewViewController(whatsNew: whatsNewExample, configuration: configuration), animated: true) ``` <img src="https://user-images.githubusercontent.com/2078225/84440787-80f36b00-ac32-11ea-9ecb-fa517f30d49f.png" width="400"/> If I alter to code to set `.original` as the image size, the image is no longer distorted but I then do not have a nice way to ensure that the images are equal width to make them align, and so the text of each item don't have aligning leading margins: <img src="https://user-images.githubusercontent.com/2078225/84440797-8650b580-ac32-11ea-99cc-2fbc322b6c5b.png" width="400" /> It would seem that the resizing code in WhatsNewItemsViewController+Cell.swift, line 207, ` func resize(height: CGFloat) -> UIImage?` doesn't do as its comment says: `/// Resize UIImage to a give height by keeping the aspect ratio`.
navan 2025-10-14 15:58:19 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github/WhatsNewKit#62
No description provided.