I’ve figured out how to create a new UI element where I touch and add it using [self.view addSubview:[uilabel reference]]. However, if I tap in the same place, it’ll simply add another subview on top of the current one.
I am able to create a unique key for each part of the grid I’m making (and thus placing subviews). Is there any way I can tag this subview with a key so I can toggle visibility on it?
Here’s some of the code:
CGRect rectNote = CGRectMake(notePosX, notePosY, noteFrameWidth - 2, noteFrameHeight - 3);
UILabel *rectNoteLabel = [[UILabel alloc] initWithFrame:rectNote];
//label settings
[self.view addSubview:rectNoteLabel];
Obviously I calculate the label’s position, which could possibly be used as a key for the subview?
UIview has a “tag” property, so yes, you can tag a view and find it again later.
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW25
Then you can call [self.view viewWithTag: blah] to get it back.
if you’re just trying to figure out if a subview exists where you’re clicking, then Jonathan Grynspan already mentioned -hitTest:
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-BBCCAICB