2010-09-30 100 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

相關問題