7
A
回答
10
您可以获得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];
+0
谢谢。我在几天前添加了这个,它效果很好! – Wizecoder 2010-10-03 17:44:44
+0
优秀的答案。奇妙的作品。 – 2012-06-26 02:42:59
相关问题
- 1. Swing:将帮助[?]按钮添加到窗口标题栏
- 2. 标签中的图像不出现在辅助窗口中(tkinter)
- 3. 如何将菜单添加到窗口的标题栏
- 4. 如何在辅助功能服务中获取当前Whatsapp窗口标题栏的名称?
- 5. 添加内容后删除窗口标题栏[Android]
- 6. 将按钮添加到窗口标题栏
- 7. 将按钮添加到工具窗口标题栏
- 8. 不能更改辅助窗口面板中的标签
- 9. 使用Cocoa在辅助显示器上显示os x窗口全屏
- 10. 在Cocoa的窗口中添加自定义视图
- 11. 在图表中添加辅助轴
- 12. 更改标题栏在Tk窗口
- 13. 将窗口标题更改为Objective-C文本框中的窗口标题?
- 14. 如何添加一些窗口标题
- 15. 使窗口窗体标题在tittle栏的中间
- 16. MDI窗口列表不更新子标题栏文本
- 17. rspec - 添加辅助模块?
- 18. 窗口绑定到文本的标题
- 19. 没有标题栏的简单窗口
- 20. 检测窗口标题栏的高度
- 21. 如何在标题栏中添加ImageButton
- 22. 在窗口的标题栏上绘制工具栏
- 23. 插头文本框到任务栏(或标题栏窗口)与C#
- 24. 如何将辅助导航栏添加到自举导航栏中
- 25. 可以在创建窗口后删除标题栏/标题吗?
- 26. 将帮助图标添加到WinForms表单标题栏
- 27. QT4拖动窗口没有标题栏
- 28. Qt C++窗口标题栏被阻止
- 29. pyqt4网页隐藏窗口标题栏
- 30. 将按钮插入窗口标题栏
的可能的复制[添加按钮窗口的顶部(OSX)](https://stackoverflow.com/questions/9955676/add-button-to-top-of-windows-osx) – 2017-07-21 18:55:33