【问题标题】:Adding secondary text to window title bar in Cocoa?将辅助文本添加到 Cocoa 中的窗口标题栏?
【发布时间】:2011-04-19 11:52:17
【问题描述】:

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

.

大家有什么建议吗?

【问题讨论】:

标签: cocoa titlebar


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多