Setting resizable UIImage to a UIImageView at viewDidLoad is ignored

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?

Answers


It looks like your UIEdgeInsetsMake() call is specifying an area of 0x0 points. Try making sure you specify a 1x1 area.

For example, your stretchable image has a size of 7x7 pixels and you want the centre pixel to stretch, you would specify edge insets like so: UIEdgeInsetsMake(3.0f, 3.0f, 3.0f, 3.0f)


Need Your Help

PermGen space in java

java

What is PermGen-space in Java? Our team has issues with PermGen-space getting increased. This increase affects performance in the end.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.