2010-09-30 48 views
7

我希望有一个试用期解除我的软件,我想知道我怎么能看出我标题栏的右侧,告诉他们,对他们的审判会持续多久,类似这样的链接:在Cocoa的窗口标题栏中添加辅助文本?

What Coda Does

任何人有任何建议吗?

+0

的可能的复制[添加按钮窗口的顶部(OSX)](https://stackoverflow.com/questions/9955676/add-button-to-top-of-windows-osx) – 2017-07-21 18:55:33

回答

10

您可以获得Windows内容视图的超级视图并为其添加自定义视图。只要确保您正确定位您的视图。下面是一些示例代码:

NSView *frameView = [[window contentView] superview]; 
NSRect frame = [frameView frame]; 

NSRect otherFrame = [otherView frame]; 
otherFrame.origin.x = NSMaxX(frame) - NSWidth(otherFrame); 
otherFrame.origin.y = NSMaxY(frame) - NSHeight(otherFrame); 
[otherView setFrame: otherFrame]; 

[frameView addSubview: otherView]; 

这里otherView是你希望把你的标题栏的视图。如果有工具栏按钮,此代码将无法工作 - 它们会重叠。幸运的是有一个API来获取工具栏按钮,这样就可以计算出位置:

NSButton *toolbarButton = [window standardWindowButton: NSWindowToolbarButton]; 
otherFrame.origin.x = NSMinX([toolbarButton frame]) - NSWidth(otherFrame); 

您还必须确保您的视图中的自动调整大小掩码设置,使其停留在右上角窗口:

[otherView setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; 
+0

谢谢。我在几天前添加了这个,它效果很好! – Wizecoder 2010-10-03 17:44:44

+0

优秀的答案。奇妙的作品。 – 2012-06-26 02:42:59