Created
December 20, 2012 15:17
-
-
Save mteece/4345871 to your computer and use it in GitHub Desktop.
Removing subviews from a view by tag.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Each UIView object has a tag property which is simply an integer value | |
| // that can be used to identify that view. You could set the tag value of | |
| // each added view to 7 like this. The use the for loop to clean up the | |
| // subview if needed. | |
| UITouch *touch = [touches anyObject]; | |
| CGPoint touchPoint = [touch locationInView:self.view]; | |
| CGRect myImageRect = CGRectMake((touchPoint.x -50), (touchPoint.y -50), 80.0f, 90.0f); | |
| UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect]; | |
| [myImage setImage:[UIImage imageNamed:@"button"]]; | |
| myImage.opaque = YES; // explicitly opaque for performance | |
| myImage.tag = 999; | |
| .... | |
| // Clear the subview by tag 999. | |
| for (UIView *subview in [self.view subviews]) { | |
| if (subview.tag == 999) { | |
| [subview removeFromSuperview]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment