0

所以我正在学习Objective C,并使用Mac Xcode 编译器。来自 Java,我习惯于手动编写 JFrame,而不是使用表单编辑器。我喜欢 Xcode 中的编辑器等等,但想知道是否有办法将代码按钮和文本框交给应用程序“表单”?从什么样的项目开始?你会从某种 FormClass 开始吗?如果是这样,如何设置interface.header。

4

1 回答 1

0

Objective C 中没有 Form 的概念。正如对您问题的评论中提到的,它是关于 View Controllers/Views 的。

是的,可以手动编码按钮和文本框。您需要在类的实现文件中执行此操作。我假设您知道 Objective C 的 .h 和 .m 是什么。

所以,要编写一个按钮,你可以这样写:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self 
         action:@selector(aMethod:)  //Method you want to call when a user taps your button
         forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Sample Button" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];

最终,在对按钮进行编码后,将其作为子视图添加到主视图中。请注意,Objective C 支持嵌套视图。因此,您可以在视图中添加一个进一步包含子视图的视图。

于 2013-04-13T01:43:59.523 回答