0

Please give me an advice.
I create UILabels programmatically (dynamic).
Is there is a chance to add Event to them?

What I want by steps:

  1. I create UILabel;
  2. I set Event to it; (NSNotification?)
  3. When I do some action (rotate, for example) I want that Label is changed or removed. An extended example: I create Labels and when I rotate device I want that part of them (which with attached Events) disappear in animation.

I create a lot of Labels, so I can't just set them global variables. And I can't set them tags unlimited. So UILabel *label = (UILabel*)[self.view viewWithTag:labelCount not a solution. Getting element by 'viewWithTag' has one more trouble - when set animation to that element and that element already in animation happens collision - they plays one over other...

I create Labels like this:

CGRect *labelFrame = CGRectMake(left, top, width, height); UILabel *label = [[UILabel alloc] initWithFrame:labelFrame]; label.text = @"Hi, I'm one of these army of labels"; [self.view addSubview:label];

PS: Sorry for English.

ExeiL
  • 15
  • 5

1 Answers1

0

I assume you have a UIViewController that has a bunch of labels. I would recommend an IBOutletConnection for storing a reference to all of your labels (assuming storyboard).

//You will need to connect all of these labels through Interface Builder.
@property (nonatomic, strong) IBOutletCollection(UILabel) NSArray *labels;

In one of the following rotation methods (Detect rotation changes in iOS) do your rearranging.

//Called whenever orientation changes
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    for (UILabel *label in self.labels) {
        //Make each label disappear here.
    }
}
Community
  • 1
  • 1
Kevin
  • 16,696
  • 7
  • 51
  • 68