Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autolayout UIImageView without image

I have a UIImageView, with scaling Center, so it's size changes according to the UIImage inside, however, by setting a nil UIImage, the constraints break, as no content size can be calculated

How to handle the autolayout with nil UIImage (the size should be changed to 0,0)?

like image 783
Peter Lapisu Avatar asked Mar 07 '14 14:03

Peter Lapisu


1 Answers

The problem is that UIImageView returns {-1, -1} as intrinsicContentSize when no image is set. Use subclass of UIImageView with implementation like this:

@implementation MyImageView

- (CGSize)intrinsicContentSize
{
    if (self.image)
    {
        return [super intrinsicContentSize];
    }

    return CGSizeZero;
}

@end
like image 111
Nikita Ivaniushchenko Avatar answered Oct 21 '22 19:10

Nikita Ivaniushchenko