Change text of label in ios camera overlay UIPickercontroller

左心房为你撑大大i 提交于 2019-12-11 10:37:34

问题


I'm trying to change though a timer in a different method the text of a label I created programmatically in a UIView overlay that goes on a UIImagePickerviewController, but of course when I try to change the text in this way

labelname.text = @"TEST";

I get the error "use of undeclared identifier labelname"

How can I refer to that specific label? Should I create a new label each time the timer ticks?

I tried to declare it in the .h file, but I'm guessing i'm just creating a different label...any ideas?


回答1:


Just Pass the Label As a whole to the Timer Function:

Say Your Label is defined in ViewDidLoad like this :

- (void)viewDidLoad 
{
     //Do Something here
     UILabel  * label = [[UILabel alloc] 
     initWithFrame:CGRectMake(xcoordinateLabel, ycoordinateLabel, width, height)];
     label.backgroundColor = [UIColor clearColor];
     label.textAlignment = UITextAlignmentCenter;
     label.textColor=[UIColor whiteColor];
     label.text = @"TEST";
     [self.view addSubview:label];
     [self changeLabelText:label];
 }

Where your changeLabelText is defined as this with some delay:

- (void) changeLabelText:(UILabel *)label
{
    //Changing Values after 10s Delay
    double delayInSeconds = 10.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 
    (int64_t)(delayInSeconds * NSEC_PER_SEC));

    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    label.text = @"TESTING Change";
    });
}

Your Timer function can replace changeLabelText



来源:https://stackoverflow.com/questions/28677769/change-text-of-label-in-ios-camera-overlay-uipickercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!