I have a UIImageView
with an image that I want to be stretchable.
In order to achieve that I do the following in viewDidLoad
:
-(void) buildResizableDescriptionAreaBackground
{
UIImage *image = [UIImage imageNamed:@"description_area_background"];
CGFloat top = ceilf(image.size.height / 2.0) - 1;
CGFloat bottom = floorf(image.size.height / 2.0);
CGFloat left = ceilf(image.size.height / 2.0) - 1;
CGFloat right = floorf(image.size.height / 2.0);
if ([image respondsToSelector:@selector(resizableImageWithCapInsets:)])
{
image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right)];
}
else
{
image = [image stretchableImageWithLeftCapWidth:left topCapHeight:top];
}
[self.descriptionAreaBackgroundImage setImage:image];
[self.descriptionAreaBackgroundImage setHighlightedImage:image];
}
When I debug this I make sure that the descriptionAreaBackgroundImage
is not nil, not hidden, alpha = 1 and with the right frame.
Also I make sure that the image is not nil, have the right size and that the resizable image is also not nil. And yet the image is not set to the UIImageView.
If I do this at viewDidAppear:
everything works fine.
If I set a regular image (Not stretchable, even at viewDidLoad
) everything works fine.
As far as I know any setup that does not require superview or window can be done at viewDidLoad
, so why isn't it working?