This commit is contained in:
zeng 2026-06-09 14:45:21 +08:00
parent 2ac2e2249b
commit 5a82e3c074

View File

@ -15,7 +15,29 @@ extension NSAlert {
static func show(_ content: String, title: String = "提示") {
let alert = NSAlert()
alert.messageText = title
if content.count > 300 || content.contains("\n") {
let scrollView = NSScrollView(frame: NSRect(x: 0, y: 0, width: 560, height: 260))
scrollView.hasVerticalScroller = true
scrollView.hasHorizontalScroller = false
scrollView.borderType = .bezelBorder
let textView = NSTextView(frame: scrollView.bounds)
textView.autoresizingMask = [.width]
textView.isEditable = false
textView.isSelectable = true
textView.drawsBackground = false
textView.textContainerInset = NSSize(width: 8, height: 8)
textView.textContainer?.widthTracksTextView = true
textView.textContainer?.containerSize = NSSize(width: scrollView.bounds.width, height: CGFloat.greatestFiniteMagnitude)
textView.string = content
textView.font = NSFont.systemFont(ofSize: 13)
scrollView.documentView = textView
alert.informativeText = "内容较长,请在下方滚动查看。"
alert.accessoryView = scrollView
} else {
alert.informativeText = content
}
alert.runModal()
}
}