1

我正在尝试编写我的第一个 iPhone 应用程序

在 Xcode 4.5.2 中,我无法将文本添加到标签

我正在尝试在下一个视频中执行该程序

http://youtu.be/0uVxxdZ5umY

它总是不起作用,错误是使用未声明的标识符“标签”

这总是在我写完之后出现 labe.text

在里面.m file

先感谢您

4

2 回答 2

0

设置按钮的 IBAction。在该方法中创建一个新的 UILabel 实例并将其添加到您的视图中。

我不确定语法。

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
label.text = @"your text";
[self.view addSubview:label]
于 2013-01-21T09:02:46.780 回答
0

最简单的方法是

UILabel *yourLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 20];
[yourLabel setTextColor:[UIColor blackColor]];
[yourLabel setBackgroundColor:[UIColor clearColor]];
[yourLabel setFont:[UIFont fontWithName: @"Trebuchet MS" size: 14.0f]]; 
[yourSuperView addSubview:yourLabel];

如果你想隐藏直到用户按下按钮。你可以做

[yourLabel setHidden:YES];
于 2013-01-21T09:22:03.310 回答