我想用基本上显示一个nsalert的附件视图。附件视图需要具有:

1)显示强制内容的nstexview

2)使用nstextview的公开按钮

披露按钮是隐藏和显示第二个nstextview所必需的。但是,同时我希望nsalert对话框调整为适应并适合内容。 Cocoa中的“保存”对话框有一个披露按钮,基本上是这样,我希望NSalert的功能相同。 建议?

有帮助吗?

解决方案

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?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top