在 Cocoa 中向窗口标题栏添加辅助文本?

发布于 2024-09-25 18:16:56 字数 147 浏览 1 评论 0原文

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

Coda 的作用

有人有什么建议吗?

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:

What Coda Does.

Anyone have any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七颜 2024-10-02 18:16:56

您可以获取 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];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文