0
MacOS의 Swift 4에 NSAlert를 사용하여 로그인 대화 상자를 구성하고 있습니다.NSAlert에 NSTextField가 여러 개 있습니다 - MacOS
func dialogOKCancel(question: String, text: String) -> (String, String) {
let alert = NSAlert()
alert.messageText = question
alert.informativeText = text
alert.alertStyle = .warning
alert.addButton(withTitle: "Login")
alert.addButton(withTitle: "Cancel")
let unameField = NSTextField(frame: NSRect(x: 0, y: 0, width: 200, height: 24))
let passField = NSSecureTextField(frame: NSRect(x: 0, y: 0, width: 200, height: 24))
let stackViewer = NSStackView()
stackViewer.addSubview(unameField)
alert.accessoryView = stackViewer
let response: NSApplication.ModalResponse = alert.runModal()
if (response == NSApplication.ModalResponse.alertFirstButtonReturn) {
return (unameField.stringValue, passField.stringValue)
} else {
return ("", "")
}
}
이 중 하나 unameField
또는 passField
내가 alert.accessoryView = passField
을 수행 할 때 보여주기 위해 잘 작동합니다 : 여기에 지금까지 가지고있는 코드입니다. 하지만 두 필드를 같은 대화 상자에 표시하려고합니다. 보시다시피 NSStackView (및 기타) 실험했지만 두 가지 요소를 모두 보여주는 솔루션을 찾지 못했습니다.
아, 물론 그것이 자신의 NSRect이 필요 해요! 정말 고맙습니다! – tornato7