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

Support sizing image views with aspect ratio preservation #135

Open
NickEntin opened this issue Aug 30, 2024 · 0 comments · May be fixed by #137
Open

Support sizing image views with aspect ratio preservation #135

NickEntin opened this issue Aug 30, 2024 · 0 comments · May be fixed by #137
Assignees
Labels
enhancement Request for a new feature or improvement to an existing feature

Comments

@NickEntin
Copy link
Collaborator

It's very common to size image views preserving their image's aspect ratio. We currently support this with the AspectRatio utility, but its call semantics are a bit awkward for this use case. In a simplified example, we end up with something like this:

imageView.bounds.size = imageView.image?.size.aspectRatio.size(toFit: bounds, in: self) ?? .zero

We should add methods calculate the sizeThatFits and to sizeToFit an image view. Additionally these should specify whether upscaling is allowed, since in many cases (e.g. when using a raster image) you want to cap the image at its native size.

func sizeThatFitsPreservingAspectRatio(_ sizeToFit: CGSize, allowingUpscaling: Bool) -> CGSize
func sizeToFitPreservingAspectRatio(_ sizeToFit: CGSize, allowingUpscaling: Bool)
@NickEntin NickEntin added the enhancement Request for a new feature or improvement to an existing feature label Aug 30, 2024
@NickEntin NickEntin self-assigned this Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Request for a new feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant