diff --git a/AppleParty/AppleParty/Shared/UI/UIExtension.swift b/AppleParty/AppleParty/Shared/UI/UIExtension.swift index 81ae907..d552593 100644 --- a/AppleParty/AppleParty/Shared/UI/UIExtension.swift +++ b/AppleParty/AppleParty/Shared/UI/UIExtension.swift @@ -15,7 +15,29 @@ extension NSAlert { static func show(_ content: String, title: String = "提示") { let alert = NSAlert() alert.messageText = title - alert.informativeText = content + 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() } }