tags:

views:

35

answers:

1

I was hoping to release my software with a trial period and I was wondering how I could show a link in the right side of my title bar telling them how long their trial will last similar to what Coda does.

Anyone have any suggestions?

+1  A: 

You can get the superview of the windows content view and add a custom view to that. Just make sure you position your view correctly. Here is some 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: textFrame];

[frameView addSubview: otherView];

Here otherView is the view you want to put in your title bar. This code won’t work though if there is a toolbar button - they would overlap. Luckily 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 also have to make sure that the autosizing masks for your view are set up so that it stays in the upper right corner of the window.

Sven
Thanks. I added this just a few days ago and it works great!
Wizecoder