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



有人有什么建议吗?

最佳答案

您可以获取Windows内容 View 的 super View ,并为其添加自定义 View 。只要确保您正确定位您的 View 即可。这是一些示例代码:

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是您要放在标题栏中的 View 。如果有工具栏按钮,则此代码将不起作用-它们会重叠。幸运的是,有一个API可以获取工具栏按钮,因此您可以计算位置:
NSButton *toolbarButton = [window standardWindowButton: NSWindowToolbarButton];
otherFrame.origin.x = NSMinX( [toolbarButton frame] ) - NSWidth( otherFrame );

您还必须确保为 View 设置了自动调整蒙版,使其位于窗口的右上角:
[otherView setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];

10-08 05:52