将 Disclosure 按钮和 NSTextView 添加到 NSAlert
我想显示一个基本上带有附件视图的 NSAlert。 Accessory 视图需要具有:
1) 用于显示强制内容的 NSTexView
2) 带有 NSTextView 的 Disclosure 按钮
Disclosure 按钮需要隐藏和显示第二个 NSTextView。但是,同时我希望 NSAlert 对话框调整大小以适应内容。 Cocoa 中的“保存”对话框有一个公开按钮,基本上可以执行此操作,我希望与 NSAlert 具有相同的功能。 建议?
I want to display an NSAlert with basically an Accessory view. The Accessory view needs to have:
1) NSTexView for displaying mandatory contents
2) Disclosure button with NSTextView
The Disclosure button is required to hide and show the second NSTextView. However, at the same time i want that NSAlert dialog resize to accomodate and fit to contents.
The Save dialog in Cocoa has a disclosure button that basically does this and i want the same functionality with NSAlert.
Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给你:
1) NSAlert 有一个 window 属性。因此使用它。
2) 创建一个包含两个 NSTextView 和一个显示三角形的自定义附件视图
3) 将此自定义视图设置为 NSAlert 的附件视图
4) 在显示警报之前,在自定义视图中设置 NSAlert 的 window 属性(这样您就可以访问单击展开三角形时 NSAlert 的窗口)
5)为展开按钮事件添加目标并保存状态(展开/折叠)
6)在展开三角形单击事件中:使用 NSAlert 保存的窗口框架来调整窗口的高度、大小和宽度NSAlert。
7)这里重要的是要注意 - 当您调整高度时, NSAlert 从顶部增长,因此您将需要相应地移动“原点”。
希望这有帮助:)。我不得不花整个周末来弄清楚如何做到这一点:D。
顺便说一句,只是出于好奇,您正在从事哪个项目或公司?
Here you go:
1) NSAlert has a window property. Hence use that.
2) Create a custom accessory view containing two NSTextView's and a disclosure triangle
3) Set this custom view as accessory view of NSAlert
4) Before displaying the alert, set the window property of NSAlert in your custom view (This way you will have access to NSAlert's window when you click disclosure triangle)
5) Add target for the disclosure button event and save the state (expanded/collapsed)
6) In the event for disclosure triangle click: Use NSAlert's saved window frame to adjust the height, size and width of NSAlert.
7) Important here is to note that - when you adjust the height, NSAlert grows from top hence you will be required to move the "origin" accordingly.
Hope this helps :). I had to spend entire weekend to figure out how to do this :D.
BTW, just out of curiosity which project or company are you working on?