Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to do something more dynamic, you could do something like:</p> <pre><code>CGRect frame = self.view.bounds; // probably better to get the parent's bounds, rather than hardcoding frame dimensions CGRect myFrame = frame; myFrame.origin.y -= 20; // I'm not sure why you're offsetting this by 20, but you really do, grab the superview's bounds and offset it self.createView = [[UIView alloc] initWithFrame:myFrame]; self.createView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:self.createView]; self.bgImgView = [[UIImageView alloc] initWithImage:image]; self.bgImgView.frame = frame; [self.createView addSubview:self.bgImgView]; self.imageViews = [[NSMutableArray alloc] init]; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSInteger i = 0; NSData *data; while ((data = [userDefaults objectForKey:[NSString stringWithFormat:@"catzero-item-%d", i++]]) != nil) { UIImage *image = [UIImage imageWithData:data]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; imageView.frame = frame; [self.createView addSubview:imageView]; [self.imageViews addObject:imageView]; } </code></pre> <p>This will read images for the keys prefixed by <code>@"catzero-item-"</code> and create image views for them. I'm also saving the individual <code>UIImageView</code> references into a <code>NSMutableArray</code> property that I've created, <code>imageViews</code>. Whether you do that is up to you.</p> <p>Having said that, there are parts of your code I don't quite get: For example, every <code>UIImageView</code> has the same frame ... I don't know why you'd create image views that will be obscured by each other, but that's up to you.</p> <p>I'd also not be inclined to store an array of images in <code>NSUserDefaults</code>, but that, again, is up to you. I'd probably be inclined to use <code>CoreData</code> or <code>SQLite</code> or a <code>plist</code> to store this array of images (or, more accurately, store the filenames there, and keep the images in the <code>Documents</code> folder). But using <code>NSUserDefaults</code> requires us to iterate through hypothetical key names, which is fragile (e.g. what if you have 3 images and then get rid of the second one ... are you going to rename all of the keys to avoid a gap in the key names). But if you use a <code>plist</code> or use <code>CoreData</code> or <code>SQLite</code>, you can iterate through a collection of images, without worrying about missing key names.</p> <p>Anyway, hopefully this gives you ideas on how to retrieve images more dynamically.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload