NSTokenField:令牌的不同颜色 [英] NSTokenField: different colors for tokens

查看:92
本文介绍了NSTokenField:令牌的不同颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在xib中创建了一个NSTokenField.我想在该tokenField中显示不同颜色的令牌.含义:某些令牌将为蓝色,其余令牌将为红色(根据其内容).有可能吗?

I have created an NSTokenField in my xib. I'd like to display tokens with different colors inside that tokenField. Meaning: some tokens will be blue, the rest will be red (according to their content). Is that possible?

以下代码对我不起作用.我希望有人能帮助我:

The following code doesn't work for me. I hope someone can help me out:

- (id)tokenField:(NSTokenField *)tokenField representedObjectForEditingString:(NSString *)editingString
{
    id returnRepresentedObject = nil;

    NSTokenFieldCell *tf = [[NSTokenFieldCell alloc] init];
    tf.stringValue = editingString;
    tf.backgroundColor = [NSColor redColor];
    returnRepresentedObject = tf;

    return returnRepresentedObject;
}

结果:所有令牌都保持蓝色...:-(

Result: all tokens remain blue... :-(

任何帮助将不胜感激!

推荐答案

您可能必须扮演自己的角色.有2010年的wwdc视频,内容涉及高级可可文字处理.NSTokenField使用NSTextAttachments呈现令牌.

You'll probably have to role your own. There is a wwdc video from 2010 about advanced Cocoa Text handling. The NSTokenField Uses NSTextAttachments to render the tokens.

这篇关于NSTokenField:令牌的不同颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆