I am using a TTImageView (from three20) to display an image from the web.
self.pic = [[TTImageView alloc] initWithFrame:CGRectMake(25, 25, 100, 100)];
self.pic.urlPath = @"http://www.google.com/images/logos/ps_logo2.png";
[self.pic sizeToFit];
NSLog(@"%f %f %f %f", self.pic.frame.origin.x, self.pic.frame.origin.y, self.pic.frame.size.width, self.pic.frame.size.height);
the image loads and displays perfectly but the NSLog returns “25.000000 25.000000 0.000000 0.000000”. How do I get this to return the correct frame?
It’s been a while since I used
TTImageView, but what I imagine is happening is the following:TTImageView will download asynchronously – that is, in the background. You need to use the delegate function
TTImageViewDelegate(documented here) to get a call back when the image has finished loading, at which point you should callsizeToFit.Currently, you’re firing off a request to download the image – a process that could take several seconds on 3G, and still a fair amount of time on WiFi- and then the next line asks to resize the frame. You need to call
sizeToFitafter you’re sure the image download has finished, which is what the delegate methods are for.