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

Bug: ImageDemoGridViewCell´s layoutSubviews #75

Open
ghost opened this issue Jun 14, 2011 · 0 comments
Open

Bug: ImageDemoGridViewCell´s layoutSubviews #75

ghost opened this issue Jun 14, 2011 · 0 comments

Comments

@ghost
Copy link

ghost commented Jun 14, 2011

Hi there,
just wanted to report a small bug in your sample project.
Having images that fulfill ( (imageSize.width <= bounds.size.width) && (imageSize.height <= bounds.size.height) ) will result in an _imageView of size CGRectZero since you return without setting it´s bounds to that of the image.
The line _imageView.frame = frame; is missing.
Thanks for great work!

- (void) layoutSubviews
{
    [super layoutSubviews];

    CGSize imageSize = _imageView.image.size;
    CGRect frame = _imageView.frame;
    CGRect bounds = self.contentView.bounds;

    if ( (imageSize.width <= bounds.size.width) &&
         (imageSize.height <= bounds.size.height) )
    {
        //This line was missing
        _imageView.frame = frame;

        return;
    }

    // scale it down to fit
    CGFloat hRatio = bounds.size.width / imageSize.width;
    CGFloat vRatio = bounds.size.height / imageSize.height;
    CGFloat ratio = MAX(hRatio, vRatio);

    frame.size.width = floorf(imageSize.width * ratio);
    frame.size.height = floorf(imageSize.height * ratio);
    frame.origin.x = floorf((bounds.size.width - frame.size.width) * 0.5);
    frame.origin.y = floorf((bounds.size.height - frame.size.height) * 0.5);
    _imageView.frame = frame;
} 
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

0 participants