iphone - 使用代码显示 UILabel 文本

标签 iphone ios ipad

我想使用代码在标签中显示浮点值

我尝试了以下代码,但它不起作用!!!!你能帮帮我吗?

找到我的代码供您引用:

 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/

相关文章:

iphone - 使用 Storyboard从 View Controller 推送 TableView Controller

ios - NSFetchedResultsController 不会自动重新加载数据

iphone - 在 TableView 中将项目标记为新添加

iphone - iOS开发: Adding an "Add Friend" button inside my app

html - 横幅高度不是仅在 iPad 上的设备高度

iphone - 检查电子邮件是否有效

javascript - 如何检查应用程序是否从 Safari 中的 JS 安装?

ios - 应用程序在快速 uisearchbar 文本输入时崩溃

iPhone 配置文件 - 项目和目标

ios - Objective-C初始化方法返回的是什么“ self ”?