Mavericks Style Marking

I'm new to cocoa, and I'm trying to figure out how I can create something similar to the new tagging interface in Mavericks:

enter image description here

I assume that I will have to rewrite NSTokenFieldCell to get colored dots or icon in tags. But how does this popup work?

Thank you for your help!

+6
source share
1 answer

Unfortunately, you have to collapse yourself. Almost all the drawings made in NSTokenFieldCell are private, so adding any decorative elements should be done by you. If I remember correctly, NSTokenFieldCell uses an NSTokenTextView instead of the standard window margin editor. Iโ€™m not sure what is different about this, but I think that this mainly concerns the specialized nature of the โ€œtokenizingโ€ attribute strings. I think they just use NSAttachmentCell objects for graphical tokens, and when the cell receives the -mouseDown: event, they show a menu.

Part of the menu will actually be quite simple, because you can add images to these menu items:

 NSMenuItem *redItem = [[NSMenuItem alloc] initWithTitle:@"Red" action:@selector(chooseColorMenuItem:) keyEquivalent:@""]; // You could add an image from your app Resources folder: NSImage *redSwatchImage = [NSImage imageNamed:@"red-menu-item-swatch"]; // ----- or ----- // You could dynamically draw a color swatch and use that as its image: NSImage *redSwatchImage = [NSImage imageWithSize:NSMakeSize(16.0, 16.0) flipped:NO drawingHandler:^BOOL(NSRect dstRect) { NSRect pathRect = NSInsetRect(dstRect, 0.5, 0.5); // Aligns border to integral values NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect:pathRect]; NSColor *fillColor = [NSColor redColor]; NSColor *strokeColor = [fillColor shadowWithLevel:0.5]; [fillColor setFill]; [path fill]; [strokeColor setStroke]; [path stroke]; return YES; }]; redItem.image = redImage; 

As for the materials with a symbolic pattern, take my information with a piece of salt, because the Apple documentation for this material is not enough, so all I am telling you is a personal fight, a curse and dizziness. Anyway, I'm sorry that I could not bring you the best news, but I think this is what it is. Good luck.

0
source

Source: https://habr.com/ru/post/958461/


All Articles