gpt4 book ai didi

cocoa - iTunes 风格的 NSWindow 子类?

转载 作者:行者123 更新时间:2023-12-03 16:10:26 25 4
gpt4 key购买 nike

Cocoa 是否有一个开源库可以创建遵循 iTunes 风格的窗口?也就是说,窗口控件是垂直布局而不是水平布局:

sample iTunes window

我发现它节省空间,适合不需要窗口标题的实用程序类型应用程序。

最佳答案

这个快速破解的 NSWindow delegate 应该可以帮助您开始:

//VerticalTrafficLightsWindowDelegate.h

#import <Cocoa/Cocoa.h>

@interface VerticalTrafficLightsWindowDelegate : NSObject <NSWindowDelegate> {
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

但是我不得不说,就像 JeremyP 一样,我只能希望 Apple 不会在 OS X 中更广泛地传播这一点。

关于cocoa - iTunes 风格的 NSWindow 子类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4304186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com