요세미티 때문에, NSStatusItem
에보기를 설정하는 방법은 사용되지 않습니다 :
여기
@implementation DragStatusView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//register for drags
[self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
//the status item will just be a yellow rectangle
[[NSColor yellowColor] set];
NSRectFill([self bounds]);
}
//we want to copy the files
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender
{
return NSDragOperationCopy;
}
//perform the drag and log the files that are dropped
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard;
NSDragOperation sourceDragMask;
sourceDragMask = [sender draggingSourceOperationMask];
pboard = [sender draggingPasteboard];
if ([[pboard types] containsObject:NSFilenamesPboardType]) {
NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
NSLog(@"Files: %@",files);
}
return YES;
}
@end
하면 상태 항목을 만들 것입니다 방법은 다음과 같습니다 여기
드래그 할 수있는 사용자 지정보기입니다 다행히
NSStatusItem
에 새로운
NSStatusItemButton
속성을 사용하는 훨씬 좋은 방법이 있습니다.
- (void)applicationDidFinishLaunching: (NSNotification *)notification {
NSImage *icon = [NSImage imageNamed:@"iconName"];
//This is the only way to be compatible to all ~30 menu styles (e.g. dark mode) available in Yosemite
[normalImage setTemplate:YES];
statusItem.button.image = normalImage;
// register with an array of types you'd like to accept
[statusItem.button.window registerForDraggedTypes:@[NSFilenamesPboardType]];
statusItem.button.window.delegate = self;
}
- (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender {
return NSDragOperationCopy;
}
- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
//drag handling logic
}
이
button
속성이 10.10에 시작하고 당신은 당신이 10.9 매버릭스 이하를 지원하는 경우 기존 솔루션을 계속해야 할 수도 있습니다 만 사용할 수 있음을 유의하시기 바랍니다.
굉장! 하지만이보기 및 쇼 메뉴를 어떻게 처리 할 수 있습니까? – Oleg
@Oleg는 클릭 처리를 구현하고이보기에 메뉴를 표시 할 수 있었습니까? –
버튼을 추가합니다. 그런 다음 DragStatusView를 하위 뷰로 추가하십시오. \t'_titleButton = [[NSButton alloc] initWithFrame : NSMakeRect (0, -2, 26, 24)]; \t [_titleButton setBordered : NO]; \t [_titleButton setButtonType : NSMomentaryChangeButton]; \t [_titleButton setImagePosition : NSImageOnly]; \t [_titleButton setBezelStyle : NSThickerSquareBezelStyle]; \t [_titleButton setTarget : self]; \t \t \t \t [_titleButton setImage : [NSImage imageNamed : @ "IconDefault.png"]]; \t \t [_titleButton setAction : @selector (showMenu :)]; \t \t \t self.view = [[ILDragStatusView alloc] initWithFrame : NSMakeRect (0, 1, 26, 24)]]; \t [self.view addSubview : _titleButton]; ' – Oleg