Skip to content

.ScaleAspectFit query could be more lucid #2

Description

@kayoslab

Very confusing implementation of the .ScaleAspectFit behaviour. This could be more lucid.

if (subview.isKindOfClass(UIImageView)) {
    if let image = imageView.image {
        if (imageView.contentMode == .ScaleAspectFit) {
            if (image.size.width > imageView.frame.size.width || image.size.height > imageView.frame.size.height) {
                if (image.size.width < image.size.height) {
                    // Landscape format
                    if (ratioWidth > imageView.frame.size.width) {
                        // Portrait does not fit into subview:UIImageView
                    } else {
                        // Portrait fits into subview:UIImageView
                    }
                } else {
                    // Portrait format
                    if (ratioHeight > imageView.frame.size.height) {
                        // Landscape does not fit into subview:UIImageView
                    } else {
                        // Landscape fits into subview:UIImageView
                    }
                }
            } else {
                // Image is smaller than subview:UIImageView
            }
        } else {
             // contentMode is not .ScaleAspectFit
        }
    }
}

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions