How to check if an image is within a particular subview.

Discussion in 'iOS Programming' started by BarryK88, Apr 13, 2011.

  1. BarryK88 macrumors member

    Mar 1, 2011
    I've got several images inside a scrollview and within my normal view. I'd like to check by means of an "if statement" if this image is inside my scrollview or not.

    i put my images inside the scroller with:

    [scroller insertSubview:image belowSubview:self.view];
    thanks in advance!
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    Images can't be inserted into views as subviews. UIImageViews, however, can. This is a significant difference.

    Are you wanting to check if a specific UIImageView is already added as a subview or if a UIImageView containing a specific image is already added?

    If it's the latter you will have to first explain how two images will be considered unique. For example:

    UIImage *image1 = [UIImage imageNamed:@"MyImage.png"];
    UIImage *image2 = [UIImage imageNamed:@"MyImage.png"];
    if (image1 != image2)
    NSLog(@"Different images");
    will log "Different images" despite both being created from the same image: it is up to you to write the code required to track which image came from which file (or which URL or whatever your image source is).
  3. BarryK88 thread starter macrumors member

    Mar 1, 2011
    this function did the job:

    [scroller.subviews containsObject:image];

Share This Page