gpt4 book ai didi

objective-c - 如何在具有 NSAttributedStrings 的 NSComboBox 中添加自动完成功能

转载 作者:行者123 更新时间:2023-12-03 17:21:57 26 4
gpt4 key购买 nike

我有一个包含 5 列的 NSTableView。其中一列具有 NSComboBoxCell。该组合框填充了许多不同颜色的字符串。所以我使用 NSAttributedStrings 将彩色字符串添加到我的组合框中。我的问题是我想向我的 NSComboBoxCell 添加自动完成功能。

之前,我通过子类化 NSComboboxCell 并覆盖 CompletedString: 方法,将所有成员都作为 NSString 的组合框做到了这一点。如何使用 NSAttributedString 实现组合框的相同效果?

最佳答案

仅使用completedString:方法并使用NSString。要更改颜色,请创建 NSValueTransformer 绑定(bind)并使用以下代码。我希望它有帮助。`

+ (Class)transformedValueClass{

return [NSAttributedString class];
}

+ (BOOL)allowsReverseTransformation{

return NO;
}

- (id)transformedValue:(id)value{

NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[NSColor redColor],NSForegroundColorAttributeName,nil];

NSAttributedString *str = [[NSAttributedString alloc] initWithString:value attributes:attributes];

return str;
}

关于objective-c - 如何在具有 NSAttributedStrings 的 NSComboBox 中添加自动完成功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22033856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com