用于创建NSTextField“label”的示例代码?

编程入门 行业动态 更新时间:2024-10-07 14:27:31
本文介绍了用于创建NSTextField“label”的示例代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的桌面Mac OS X应用程序,我想编程创建一个NSTextField标签,它具有与Interface Builder中创建的典型标签相同的行为和属性。

In my desktop Mac OS X app, I'd like to programatically create a NSTextField "label" which has the same behavior and properties as a typical label created in Interface Builder.

我通常使用(非常喜欢)IB,但在这种情况下,必须以程序化的方式完成。

I usually use (and very much like) IB, but in this case it must be done programatically.

可能,我似乎找不到方法调用的组合,将编程产生与从IB视图库调色板拖动的标签相同的label-y行为。

Try as I might, I can't seem to find the combination of method calls that will programatically produce the same label-y behavior as a "Label" dragged from the IB View Library palette.

任何人都可以提供或指出一些如何做这个程序的示例代码? Thx。

Can anyone provide or point out some example code of how to do this programatically? Thx.

推荐答案

标签实际上是 NSTextField ,NSView的子类。因此,由于它是一个NSView,它必须添加到另一个视图。

A label is actually an instance of NSTextField, a subclass of NSView. So, since it is a NSView, it has to be added to another view.

这是一个工作代码:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSTextField *textField; textField = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 10, 200, 17)]; [textField setStringValue:@"My Label"]; [textField setBezeled:NO]; [textField setDrawsBackground:NO]; [textField setEditable:NO]; [textField setSelectable:NO]; [view addSubview:textField]; }

更多推荐

用于创建NSTextField“label”的示例代码?

本文发布于:2023-11-28 04:32:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:示例   代码   NSTextField   label

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!