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 this:
.
Anyone have any suggestions?
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: otherFrame];
[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:
[otherView setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With