objective c - iOS Load image from URL specifying size -


recently our app needs replacement in image fetching logic, such client should request image size (image built server dynamically).

image url has following format: http://image.server.url/path?width={{width}}&height={{height}}

most of custom views built in following pattern:

- (instancetype)initwithframe:(cgrect)frame {     if (self = [super initwithframe:frame]) {         // initializations     }     return self; }  - (void)setimageurl:(nsurl *)url {     // image fetching } 

and instantiated as:

someview *view = [[someview alloc] init]; view.imageurl = [nsurl urlwithstring:@"..."]; [self addsubview:view]; 

this not problem (as images' size static), when requesting image having dynamic size unavailable because, image fetching run before -layoutsubviews called, target image container's size zero.

after all, need figure out timing when layout finished (using observer image containers), or have static size image containers.

what best solution this?

i believe, maybe don't need "exact" size of image, because image scaled or down. in opinion need close enough size of image. because (as guess) image size determined screen size, (which determined device), prepare function images, return right size right device.

you can know ab front sizes iphone 4, iphone 5,.... , load correct size of image (which container load after layoutsubviews)

second idea (as xaphod mention) load sizes when app downloaded , load correct size in layoutsubviews. aware, if there lot of images in lot of sizes, huge space consumption images never placed in app.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -