向Cocoa中的窗口标题栏添加次级文本? [英] Adding secondary text to window title bar in Cocoa?

查看:299
本文介绍了向Cocoa中的窗口标题栏添加次级文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在试用期内发布我的软件,我想知道如何在标题栏的右侧显示链接,告诉他们他们的试用期将持续多长时间类似于:

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:

任何人都有任何建议?

推荐答案

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

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

这里 otherView 放在您的标题栏。这个代码不会工作,虽然如果有一个工具栏按钮 - 他们会重叠。幸运的是有一个API来获取工具栏按钮,以便您可以计算位置:

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

这篇关于向Cocoa中的窗口标题栏添加次级文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆