如何使用 Objective-C 或 MacRuby 自定义令牌 - Cocoa
我尝试构建一个能够在行首显示一个或多个令牌的输入。
您可以在下图中看到我试图接收的示例。 (屏幕截图显示 google-macsearch)
http://www.freeimagehosting。 net/uploads/4a268855a0.jpg
Cocoa提供了NSToken类,但我喜欢自己做和自定义,但我不知道做什么或怎么做。
我想抽出令牌。这工作正常,但现在它在我的视图上并且没有任何功能。我希望我能以某种方式将它放入 TextView 中。 我希望你能给我一个提示。
敬礼
I try to build an Input which is able to show one or more Token at the beginning of line.
You can see an example what I'm trying to receive in the image below. (screenshot shows google-macsearch)
http://www.freeimagehosting.net/uploads/4a268855a0.jpg
Cocoa provides the NSToken class, but I like to do it by myself and custom, but I don't know what or how to do.
I tempt to draw the Token. This works fine, but now its on my View and without any functionality. I expect i shout place it somehow into the TextView.
I hope you will give me a hint.
Salut
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是
NSTokenField
类是用于。基本上,令牌字段向其委托询问有关其令牌的信息,然后自行绘制令牌。This is what the
NSTokenField
class is for. Basically, the token field asks its delegate for information about its tokens, and then draws the tokens itself.有一个示例,稍加调整即可对您有所帮助。
SSToken - 自定义 NSTokenField
下载示例,您会发现一个名为 SSToken 的类。将课程包含在您的项目中。
由于 SSToken 是基于与 NSTextField 的组合而构建的,并且界面与 NSTokenField 类似,因此您可以更轻松地自定义令牌并以您想要的方式显示它。
它还通过添加新令牌来垂直增长,就像在本机邮件应用程序中一样。
There is a sample, a little tweak can help in your way.
SSToken - A custom NSTokenField
Download the sample, you will find a class called SSToken. Include the class in your project.
Since SSToken is built on composition with NSTextField and interface is similar like NSTokenField, it would be easier for you to customise the tokens and show it in the way you wanted.
It also grows vertically on adding new tokens like in native Mail App.