- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建 cocoa 应用程序,其中我像这样以编程方式创建了NSTextField
,
NSView *superView = [[NSView alloc] initWithFrame:NSMakeRect(0, 300, 1400, 500)];
NSTextField *myTextField = [[NSTextField alloc] initWithFrame:NSMakeRect(180, 100, 1000, 300)];
[myTextField setStringValue:myText];
[myTextField setEditable:NO];
[myTextField setBezeled:NO];
[myTextField setDrawsBackground:NO];
[myTextField setSelectable:NO];
[myTextField setFont:[NSFont fontWithName:@"Futura" size:22]];
[superView addSubview:myTextField];
[superView setAutoresizesSubviews:YES];
[myTextField setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[self.window.contentView addSubview:superView];
现在我想要文本垂直对齐,并且应该可以根据文本长度进行调整。
有人有什么建议吗?请分享您的建议:)
非常感谢..!!
最佳答案
您想要的是可能的,但是您必须创建 NSTextFieldCell 的子类,然后在 NSTextField 中使用该子类。您想要重写的关键方法是 drawingRectForBounds:
、selectWithFrame:
和 editWithFrame:
Here is a blog post from the fantastic Daniel Jalkut关于这一点,他甚至提供了一个可供下载的版本。该帖子相当旧,但应该仍然可以正常工作。
关于xcode - NSTextField 垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10205088/
我有 NSTextField 但我必须显示的内容不是固定的,它会动态增长。有什么简单的方法可以动态改变大小。提前致谢:) 最佳答案 文本字段的委托(delegate)需要随着文本的变化而更新大小。 诀
我正在尝试实现一个自定义的NSTextField,它a)在事件时改变颜色,b)在左上角有一个标签。 我有以下实现: 在TestTextField.h @interface TestTextField
我有大约 10 个按钮,每个按钮都有不同的名称。在选择每个按钮时,我需要将按钮的标题附加到 NSTextField,而不删除旧字符串。 我试过以下方法。 - (IBAction)nextButton:
我有一个 NSSlider,它可以更新 NSTextField 的内容。到目前为止,一切都很好。只要 NSTextField 没有聚焦或被用户编辑(键入或保持空白等),它就可以工作。 我想要做的是通过
我在从不同类中的 NSTExtField 访问值时遇到问题,这里是代码: AppDelegate.h #import @interface AppDelegate : NSObject @prop
我正在制作一个登录页面,当我得到用户输入时它很好。凭据将存储在一个文件中。存储在文件中的值被设置为 NSTextField 的字符串。 . 如果我使用 NSSecureTextField当我从文件中读
我正在尝试在其窗口委托(delegate)中访问 NSTextField 实例的复制、剪切和粘贴方法,以便我可以自定义这些方法。我发现与 tableViews 和 textViews 不同,文本字段的
我正在尝试创建一个 NSTextField 以允许批量重命名某些文件。该字段应该允许插入一些标记来自定义每个文件名。 NSTokenField 的问题在于 1)它会修剪空白,这是应该允许的,2)它没有
我的 XIB 文件中有一个文本字段标签,用于显示我想要动态加载的一些文本。这是我的应用程序的当前流程: -在 XIB 文件中,文本字段设置为静态文本- 运行应用程序时,窗口会加载文本字段和静态文本-加
我的应用程序有 NSTextFields 用于输入;我故意不使用 NSNumberFormatter 来对输入进行特殊处理。该应用程序实现“全屏”模式。当应用程序处于全屏状态并且焦点位于文本字段中时,
我有一个 NSTextField 的自定义子类。我想在右键单击时显示上下文菜单,但该菜单显示完全不相关的服务菜单。我知道这是由于操作系统设置而添加的,但这些选项在我的场景中根本没有用(例如,文本字段包
我如何知道 NSTextField 何时获得焦点? 是否有一个委托(delegate)方法可以告诉我用户何时在我的 NSTextField 中单击鼠标(或以其他方式选择)? 谢谢 汤姆 最佳答案 子类
我有一个 NSTextField 和 Label,其值绑定(bind)到 View Controller 中的相同 NSString 这里的问题是标签只有在我按 Tab 时才会更新。 如何使其连续,以
我之前设置过,但现在找不到这个选项了... alt text http://www.joelsaltzman.com/pics/ib.png 最佳答案 当您使用绑定(bind)连接文本字段时,该选项可
我的 NSTextField 子类遇到一些问题。这是一个用于输入一些消息的文本字段。当我的子文本字段是第一响应者并且用户按下热键 Cmd + Enter 时,我的应用程序必须发送此消息。我无法使用 C
如何在 NSTextField 的左侧添加搜索图标?您可以在许多其他应用程序中看到同样的情况。 最佳答案 我猜是这样的: text = NSTextField.alloc().initWithFram
我正在使用两个 NSTextFields 作为用户名和密码。通常它工作正常,但有时当我切换出用户名文本字段时,用户名中的文本消失,但字符串值仍然存在。当我切换回“用户名”文本字段时,该文本会重新出现,
当我使用时 [myNSTextField setStringValue:@"AAA"]; 设置 NSTextField 的文本 文本始终具有黑色背景,看起来像是已被选中。是否可以显示黑色文本颜色和白色
我正在尝试使用 NSTextField 制作一个简单的动画 - (void)bounceTimeLabel { // Create a key frame animation C
我得到了一个 NSTextField,它看起来很好,直到它放弃了第一个响应者。 它会绘制一个白色矩形,直到再次成为第一响应者。知道如何避免这种情况吗? 最佳答案 绘图问题似乎是由 TextField
我是一名优秀的程序员,十分优秀!