nstokenfield

NSTokenField: different colors for tokens

被刻印的时光 ゝ 提交于 2021-02-08 05:19:13
问题 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

Custom-drawn tokens in NSTokenField

不打扰是莪最后的温柔 提交于 2021-01-27 12:29:31
问题 Is there a way to have custom tokens inside an NSTokenField ? By "custom" I mean I would like to draw them in a custom way -- custom hover, background image, etc. 回答1: Yes, this is possible, but you'll have to resort to using private APIs, which you don't want if you intend on publishing your app to the Mac App Store. I have contacted Apple about this, and they have confirmed that there is no way of doing this without private APIs - if one needs difference appearance using only public APIs,

How to make an NSControl (e.g., NSTokenField) ignore mouse events

℡╲_俬逩灬. 提交于 2020-01-06 03:49:25
问题 Specifically, I'd like to make an NSTokenField ignore mouse events because I'm using it in a NSTableCellView just to display data in a tokenized way without allowing any editing. Setting the token field's enabled = NO works, except that it greys out the tokens and makes it hard to read the text. Setting the token field's editable = NO is pretty close to what I want—it prevents editing while preserving the token field's look—except that when I mouse over the tokens, they light up. If I could

Clicking token in NSTokenField

↘锁芯ラ 提交于 2020-01-01 09:43:24
问题 Is it possible to get an event when you click on a token in a NSTokenField? 回答1: Seeing as those tokens ( NSTokenFieldCell s) inherit from the NSCell class, in theory, yes, you can have them send an event by giving them an action and a target ( -setAction: and -setTarget: respectively, and if you want to give the tokens menus when pressed, use -setMenu: ). 来源: https://stackoverflow.com/questions/4588599/clicking-token-in-nstokenfield

Auto-resizing NSTokenField with constraint-based layout

浪子不回头ぞ 提交于 2019-12-24 09:49:26
问题 Is there any way to automatically resize the height of a NSTokenField (keeping the width constant) using constraints? -sizeToFit should work, but it doesn't. If I set a constraint to keep the width constant and call this method it ignores the constraints and resizes the width only (when what I want is to resize the height only). 回答1: The cellSizeForBounds method of the token field does return the correct size, so you can implement it like this (custom subclass, in Swift): class TagsTokenField

NSTokenField catch some NSEvents

好久不见. 提交于 2019-12-20 06:41:21
问题 I need implement Command + Enter, Command + O and Esc shotcuts for NSTokenField and solutonns like https://stackoverflow.com/a/18486965/1067147 not worked because -(void)noop:(SEL)sel isn't useful. 回答1: My way is to create category for upper-in-hierarchy class NSView (also I try it for NSTextView but no luck): // NSView+WideInterpreter.h #import <Cocoa/Cocoa.h> #define kNotificationTokenModifier @"kNotificationTokenModifier" #define kNotificationTokenModifier_modifier @

NSTokenField does not let me type other strings than tokenField:completionsForSubstring:… returns

烈酒焚心 提交于 2019-12-19 09:58:12
问题 My issue is that NSTokenField does not allow me to type any text I want, it's only allow me to type strings that are included in the NSArray that tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: returns. - (NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex { return [NSArray arrayWithObjects:@"AA", @"BB", @"CC", @"DD", nil]; } My NSTokenField can

NSTokenField does not let me type other strings than tokenField:completionsForSubstring:… returns

岁酱吖の 提交于 2019-12-19 09:58:08
问题 My issue is that NSTokenField does not allow me to type any text I want, it's only allow me to type strings that are included in the NSArray that tokenField:completionsForSubstring:indexOfToken:indexOfSelectedItem: returns. - (NSArray *)tokenField:(NSTokenField *)tokenField completionsForSubstring:(NSString *)substring indexOfToken:(NSInteger)tokenIndex indexOfSelectedItem:(NSInteger *)selectedIndex { return [NSArray arrayWithObjects:@"AA", @"BB", @"CC", @"DD", nil]; } My NSTokenField can

How to Limit the Number of Tokens in a NSTokenField?

大兔子大兔子 提交于 2019-12-10 20:37:01
问题 I have a NSTokenField Where the tokens are created upon hitting enter. I would like to limit the number of tokens in this field. Say for example, User should be allowed to enter only 2 tokens one after the other. Later, neither user should be allowed to set the Token nor user should be allowed to search further. In short, User should be blocked after 2 tokens. Could any one please help me in achieving this??? Thanks in advance :) 回答1: The solution is divided in 2 parts: -(NSArray *)tokenField

How to validate all tokens are valid in an NSTokenField

孤街浪徒 提交于 2019-12-10 12:47:38
问题 Apple have conveniently created a callback method that allows you to check that the new tokens that are being added to an NSTokenField are valid: - (NSArray *)tokenField:(NSTokenField *)tokenField shouldAddObjects:(NSArray *)newTokens atIndex:(NSUInteger)index I have implemented this, and it turns out that it works great except for in one case. If the user starts typing in a token, but has not yet completed typing the token, and the user presses the TAB key, the validation method is not