lascic / UIOnboarding

Apple-esque animated welcome screen for iOS and iPadOS. Configurable.
MIT License
713 stars 28 forks source link

Image in notice area too big #7

Closed hensch7 closed 2 years ago

hensch7 commented 2 years ago

Hey,

I noticed, that when you put an image into the notice area, it doesn't get properly resized and is way too big. The images next to the bullet points get resized to fit, but the notice image is shown as is.

The only fix right now is manually downsizing the image, but it should work as it does with all other images.

Example:

Simulator Screen Shot - iPhone 13 - 2022-07-22 at 14 00 24

lascic commented 2 years ago

Hey, thanks for reporting this issue. On a high level, the reason why the image is too big is because it's embedded in an NSMutableAttributedString (as NSTextAttachment) and not in a UIImageView instance. I'll have to rethink the UI there and will fix that in a future update.

For the time being, you can...

or

extension UIImage {    
    enum ContentMode {
        case contentFill
        case contentAspectFill
        case contentAspectFit
    }

    func resize(withSize size: CGSize, contentMode: ContentMode = .contentAspectFill) -> UIImage? {
        let aspectWidth = size.width / self.size.width
        let aspectHeight = size.height / self.size.height

        switch contentMode {
        case .contentFill:
            return resize(withSize: size)
        case .contentAspectFit:
            let aspectRatio = min(aspectWidth, aspectHeight)
            return resize(withSize: CGSize(width: self.size.width * aspectRatio, height: self.size.height * aspectRatio))
        case .contentAspectFill:
            let aspectRatio = max(aspectWidth, aspectHeight)
            return resize(withSize: CGSize(width: self.size.width * aspectRatio, height: self.size.height * aspectRatio))
        }
    }

    private func resize(withSize size: CGSize) -> UIImage? {
        UIGraphicsBeginImageContextWithOptions(size, false, self.scale)
        defer { UIGraphicsEndImageContext() }
        draw(in: CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height))
        return UIGraphicsGetImageFromCurrentImageContext()
    }
}

Thank you for your support.

lascic commented 2 years ago

Fixed in 985953d.

Will be included in an upcoming release.