Adding secondary text to window title bar in Cocoa?

I was hoping to release my trial software, and I was wondering how I can show the link on the right side of my header bar, telling them how long their trial lasts:

What coda does .

Anyone have any suggestions?

+7
cocoa titlebar
source share
1 answer

You can get an idea of ​​viewing Windows content and add a custom look to it. Just make sure you position your eyes correctly. Here is a sample code:

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]; 

Here otherView is the view you want to put in your title bar. This code will not work if there is a button on the toolbar - they will overlap. Fortunately, there is an API to get the toolbar button so you can calculate the position:

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

You should also make sure that the auto-image masks for your view are configured so that they remain in the upper right corner of the window:

 [otherView setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; 
+10
source share

All Articles