UIOnboarding icon indicating copy to clipboard operation
UIOnboarding copied to clipboard

Image in notice area too big

Open hensch7 opened this issue 2 years ago • 1 comments

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

hensch7 avatar Jul 22 '22 12:07 hensch7

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...

  • use an SFSymbols image.
  • manually resize your image in a photo editing tool of your choice (Photoshop, Pixelmator, Affinity Photo, within Xcode etc.).

or

  • programmatically resize your image as shown in an extension of UIImage below.
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 avatar Jul 28 '22 14:07 lascic

Fixed in 985953d.

Will be included in an upcoming release.

lascic avatar Oct 24 '22 06:10 lascic