iTunes-style NSWindow subclass?

后端 未结 3 1114
南方客
南方客 2020-12-08 12:52

Is there an open-source library for Cocoa to create a window following iTunes\' style? That is the window controls are laid out vertically instead of horizontally:

3条回答
  •  醉梦人生
    2020-12-08 12:59

    This quickly hacked away NSWindow delegate should get you started:

    //VerticalTrafficLightsWindowDelegate.h
    
    #import 
    
    @interface VerticalTrafficLightsWindowDelegate : NSObject  {
        NSWindow *window;
    }
    
    @property (assign) IBOutlet NSWindow *window;
    
    - (void)verticalizeButtonsForWindow:(NSWindow *)aWindow;
    
    @end
    
    //VerticalTrafficLightsWindowDelegate.m
    
    #import "VerticalTrafficLightsWindowDelegate.h"
    
    @implementation VerticalTrafficLightsWindowDelegate
    
    @synthesize window;
    
    - (void)awakeFromNib {
        [self verticalizeButtonsForWindow:window];
    }
    
    - (void)windowDidResize:(NSNotification *)notification {
        [self verticalizeButtonsForWindow:window];
    }
    
    - (void)verticalizeButtonsForWindow:(NSWindow *)aWindow {
        NSArray *contentSuperViews = [[[aWindow contentView] superview] subviews];
    
        NSView *closeButton = [contentSuperViews objectAtIndex:0];
        NSRect closeButtonFrame = [closeButton frame];
    
        NSView *minimizeButton = [contentSuperViews objectAtIndex:2];
        NSRect minimizeButtonFrame = [minimizeButton frame];
    
        NSView *zoomButton = [contentSuperViews objectAtIndex:1];
        NSRect zoomButtonFrame = [zoomButton frame];
    
        [minimizeButton setFrame:NSMakeRect(closeButtonFrame.origin.x, closeButtonFrame.origin.y - 20.0, minimizeButtonFrame.size.width, minimizeButtonFrame.size.height)];
        [zoomButton setFrame:NSMakeRect(closeButtonFrame.origin.x, closeButtonFrame.origin.y - 40.0, zoomButtonFrame.size.width, zoomButtonFrame.size.height)];
    }
    
    @end
    

    However I got to say that just like JeremyP I can only hope Apple's not going to spread this any wider in OS X.

提交回复
热议问题