Prasan
Prasan

Reputation: 111

Old label text doesn't get cleared when I use the UIColor clearColor method in Xcode 4.5.2. The new text is getting superimposed on the old

Old label text doesn't get cleared when I use the UIColor clearColor method in Xcode 4.5.2. The new text is getting superimposed on the old.

Here is my code below. Whenever I press restart, I want my labels to get reset to @"". But it is not getting cleared.

        CGRect frame=CGRectMake(intX, intY, 15, 18);
        UILabel *label = [[UILabel alloc] initWithFrame:frame];
        [self.view addSubview:label];
        [label setFont:[UIFont fontWithName:@"ChalkboardSE-Light" size:17]];

        CGRect frame1=CGRectMake(intSerialNoX, intY, 20, 18);
        UILabel *label1 = [[UILabel alloc] initWithFrame:frame1];
        [self.view addSubview:label1];
        [label1 setFont:[UIFont fontWithName:@"ChalkboardSE-Light" size:17]];

        label1.textColor = color;

        label.backgroundColor=[UIColor clearColor];
        label1.backgroundColor=[UIColor clearColor];

        if([strAction isEqualToString:@"GO"])
        {
            [label1 setText:[myLableSerialNoArray objectAtIndex:i]];
            [label setText:[[myLableWordsArray objectAtIndex:i] substringWithRange:NSMakeRange(j,1)]];
        }
        else if([strAction isEqualToString:@"RESTART"])
        {
            [label1 setText:@""];
            [label setText:@""];
        }

Upvotes: 1

Views: 139

Answers (1)

foundry
foundry

Reputation: 31745

Have you set breakpoints to be sure [label1 setText:@""]; is getting called?

In any case I think the problem is that you are alloc and init'ing new labels every time this method is called, and placing them on top of labels that are already there from previous calls to the same method. You probably only want to do the alloc/init once, and then add a property to hold a reference to each label, which you can then use inside the method to set / reset the text.

Upvotes: 1

Related Questions