Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image in notice area too big #7

Closed
hensch7 opened this issue Jul 22, 2022 · 2 comments
Closed

Image in notice area too big #7

hensch7 opened this issue Jul 22, 2022 · 2 comments

Comments

@hensch7
Copy link

hensch7 commented Jul 22, 2022

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
Copy link
Owner

lascic commented Jul 28, 2022

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
Copy link
Owner

lascic commented Oct 24, 2022

Fixed in 985953d.

Will be included in an upcoming release.

@lascic lascic closed this as completed Oct 24, 2022
lascic added a commit that referenced this issue Jan 29, 2023
Notice configuration as a whole is now optional (#11). In addition, one can also set up notice elements based on their own needs: All elements, except the notice text, are now optional.

This version also fixes oversized notice icons by improving constraint layout rules (#7).
lascic added a commit that referenced this issue Aug 8, 2023
Notice configuration as a whole is now optional (#11). In addition, one can also set up notice elements based on their own needs: All elements, except the notice text, are now optional.

This version also fixes oversized notice icons by improving constraint layout rules (#7).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants