我想使用代码在标签中显示浮点值
我尝试了以下代码,但它不起作用!!!!你能帮帮我吗?
找到我的代码供您引用:
UILabel * label;
float a;
a=2;
{ label = [self valueForKey:[NSString stringWithFormat:@"A:%d", a]];}
但它给出了一个错误 :SIGABRT
最佳答案
首先你应该创建标签,然后将格式化文本设置为 text
属性,然后在你的 View 上显示(self.view 假设你将它用于 UIViewController)
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
[label setText:[NSString stringWithFormat:@"%f", a]];
[self.view addSubview:label];
[label release];
关于iphone - 使用代码显示 UILabel 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9060774/