BarryK88
BarryK88

Reputation: 1806

How to check if an image is within a particular subview

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!

Upvotes: 0

Views: 162

Answers (3)

ax123man
ax123man

Reputation: 578

something like:

UIView *parent = [self.imageView superview];
if (parent == scroller) {
    //yep
}

Upvotes: 0

Tovi7
Tovi7

Reputation: 2953

Have you tried:

[scroller.subviews containsObject:image];

?

Upvotes: 1

knuku
knuku

Reputation: 6102

If you want to add an image only if it is not added yet you can use tags. Each UIImageView should have a unique tag.

const int uniqueImageTag = 10001;
image.tag = uniqueImageTag;
if ([scroller viewWithTag:imageTag] == nil) {
    [scroller insertSubview:image belowSubview:self.view];
}

Upvotes: 0

Related Questions