SvenTiigi / WhatsNewKit

Showcase your awesome new app features 📱
https://sventiigi.github.io/WhatsNewKit/
MIT License
3.87k stars 190 forks source link

Aspect ratio not preserved when using fixed imageSize #41

Closed AndrewBennet closed 4 years ago

AndrewBennet commented 4 years ago

WhatsNewKit Environment

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.

AndrewBennet commented 4 years ago

This seems like a great project though, thanks for making it! I'm hoping to add it in to my app Reading List, but I'd much rather use iOS 13 SFSymbols than have to source my own images. I can use the original size setting, but the non-aligning text bugs me.

SvenTiigi commented 4 years ago

Hey @AndrewBennet

Thank you for your detailed bug report. I will investigate the reported bug and respond back if a fix is available ✌️

AndrewBennet commented 4 years ago

Hi Sven -- I've had a quite go at improving this, and submitted the change as a pull request: https://github.com/SvenTiigi/WhatsNewKit/pull/42

Running the example app with the images swapped out for SFSymbol images, I see better results now: no distorted images, and no misaligned text.

SvenTiigi commented 4 years ago

@AndrewBennet your PR (https://github.com/SvenTiigi/WhatsNewKit/pull/42) has been merged and a new release of WhatsNewKit is now available 1.3.4