title: How to change the UIImageView image content by code?
body: <p>I use this to assign image:</p>
  
  <pre><code>UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"]];
  CGRect cropRect = CGRectMake(175, 0, 175, 175);
  CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], cropRect);
  imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 175, 175)];
  imageView.image = [UIImage imageWithCGImage:imageRef];
  [self addSubview:imageView];
  CGImageRelease(imageRef);
  </code></pre>
  
  <p>Now, I want to change the image from myImage to myImage2, so I do that:</p>
  
  <pre><code>    UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"myImage2" ofType:@"png"]];
  CGRect cropRect = CGRectMake(175, 0, 175, 175);
  CGImageRef imageRef = CGImageCreateWithImageInRect([img CGImage], cropRect);
  imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 175, 175)];
  imageView.image = [UIImage imageWithCGImage:imageRef];
  [self addSubview:imageView];
  </code></pre>
  
  <p>It works, but not the way I want, I want to change the image, not add a imageView on top of the pervious one. How can I modify my code? thx u.</p>