iTunes-style NSWindow subclass?

后端 未结 3 1206
南方客
南方客 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条回答
  •  猫巷女王i
    2020-12-08 13:01

    Just a modified version based on @Regexident 's for new macOS. The view hierarchy changed for new macOS UI, so the original version does not work. The modified code is as follows (works on macOS 10.13):

    - (void)verticalizeButtonsForWindow:(NSWindow *)aWindow {
        // New view hierarchy.
        NSView *titleBarContainerView = aWindow.contentView.superview.subviews[1];
        titleBarContainerView.frame = NSMakeRect(titleBarContainerView.frame.origin.x, titleBarContainerView.frame.origin.y - 60.0 + titleBarContainerView.frame.size.height, titleBarContainerView.frame.size.width, 60.0);
        NSView *titleBarView = titleBarContainerView.subviews[0];
        titleBarView.frame = NSMakeRect(0.0, 0.0, titleBarView.frame.size.width, 60.0);
        NSArray *titleBarSubviews = titleBarView.subviews;
    
        NSView *closeButton = [titleBarSubviews objectAtIndex:0];
        NSRect closeButtonFrame = [closeButton frame];
    
        NSView *minimizeButton = [titleBarSubviews objectAtIndex:2];
        NSRect minimizeButtonFrame = [minimizeButton frame];
    
        NSView *zoomButton = [titleBarSubviews objectAtIndex:1];
        NSRect zoomButtonFrame = [zoomButton frame];
    
        // Coordinate changed: add instead of minus.
        [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)];
    }
    

    Result screenshot:

提交回复
热议问题