【发布时间】:2014-05-07 09:17:07
【问题描述】:
首先,我是 xcode 和 Objective-c 编程的初学者。我用导航栏制作了我的应用程序,我有 UIView 和 Class1 类,我添加了新的子视图 Level1,但我不想添加新类。是否有任何解决方案如何从 ClassLesson1.m 向子视图 Level1 添加标签?
谢谢
【问题讨论】:
标签: objective-c xcode uiview
首先,我是 xcode 和 Objective-c 编程的初学者。我用导航栏制作了我的应用程序,我有 UIView 和 Class1 类,我添加了新的子视图 Level1,但我不想添加新类。是否有任何解决方案如何从 ClassLesson1.m 向子视图 Level1 添加标签?
谢谢
【问题讨论】:
标签: objective-c xcode uiview
这样做很容易。让我们承认这是您的第 1 课视图代码。在 viewDidLoad 方法中你可以添加任何你想要的。
- (void)viewDidLoad
{
UIView *level1 = [[UIView alloc] initWithFrame:CGRectMake(x,y,width,height)];
[self.view addSubview:level1]
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(label_x,label_y,label_width,label_height)];
label1.text = @"labeltext";
[level1 addSubview:label1]
}
【讨论】:
是的,你可以。
以编程方式:
// viewDidLoad method from Lesson1 class
- (void)viewDidLoad
{
self.level1 = // Your UIView
[self.view addSubview:self.level1]
[self.level1 addSubview:yourLabel]
}
在第 1 课中使用 XIB 文件:
将 UILabel 拖放到您的第 1 课中,并将 UILabel 与第 1 课上的 IBoutlet 链接。
【讨论】:
使用下面的链接。可能对你有帮助!! http://www.techotopia.com/index.php/An_iOS_7_Core_Data_Tutorial
【讨论】: