在ios相机叠加层UIPickercontroller中更改标签的文本 [英] Change text of label in ios camera overlay UIPickercontroller
问题描述
我正在尝试通过计时器以其他方法更改我在UIImagePickerviewController上的UIView覆盖层中以编程方式创建的标签文本,但是当然,当我尝试以这种方式更改文本时
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";
labelname.text = @"TEST";
我收到错误消息使用未声明的标识符labelname
"
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?
我试图在.h文件中声明它,但是我想我只是在创建一个不同的标签...有什么想法吗?
I tried to declare it in the .h file, but I'm guessing i'm just creating a different label...any ideas?
推荐答案
只需将标签整体传递给Timer函数:
Just Pass the Label As a whole to the Timer Function:
说您的标签是在ViewDidLoad中定义的,就像这样:
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];
}
其中的changeLabelText定义如下:
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";
});
}
您的Timer函数可以替换changeLabelText
Your Timer function can replace changeLabelText
这篇关于在ios相机叠加层UIPickercontroller中更改标签的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!