【问题标题】:NSTextField - Selectable and mouseup eventNSTextField - 可选择和 mouseup 事件
【发布时间】:2017-05-05 18:49:45
【问题描述】:

我已经创建了自己的 NSTextField 对象:

@interface MyTitleLabel: NSTextField
@end

@implementation MyTitleLabel
- (void)mouseUp:(NSEvent *)event {
    NSLog(@"up");
}
@end

然后像这样初始化它:

MyTitleLabel* title_field = [[MyTitleLabel alloc] init];

问题是如果我有:

[title_field setSelectable:YES];

mouseUp 事件触发。但如果我将它设置为NO,它就是。但是我需要 NSTextField 成为 selectable 并有一个 mouseUp 事件?

我还有一个问题是,一旦我在 NSTextField 中选择了一些文本,就不会调用 - (void) rightMouseDown:(NSEvent *)event;

【问题讨论】:

  • 你的最终目标是什么?当你的MyTitleLabel 成为第一响应者时,听起来你想听。
  • 我希望我的 nstitlelabel 的行为与 HTML 链接的工作方式相同。我目前可以点击它选择标签的文本不是两者
  • 使用attributedStringValue 和带有NSLinkAttributeName 属性的属性字符串。
  • @Willeke 是的,但我不希望用户能够编辑它...
  • editable 设置为NO

标签: objective-c macos cocoa nstextfield


【解决方案1】:

文本字段的功能由完成大部分工作的 NSTextFieldCell 和拥有它的控件 NSTextField 实现。

此外,在编辑时,字段编辑器也会发挥作用。

Apple 的文档解释了这种关系:

https://developer.apple.com/library/content/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TextFieldsAndViews/TextFieldsAndViews.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 2023-01-23
    • 2011-05-24
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    相关资源
    最近更新 更多