我有一个简单的WKWebView应用程序,它使用AppKit中的SwiftUI在macOS上打开了一个网站。
但是,应用程序窗口没有标题-我说的是第一行(用红色的X来关闭它,依此类推。
如何在那里设置标题?我尝试查看Main.Storyboard,但没有看到任何类似于“标题段”的内容。
最佳答案
窗口是使用AppDelegate
创建的,因此您可以按照以下步骤进行操作...
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
// Create the window and set the content view.
window = NSWindow(
contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered, defer: false)
window.title = "Some title" // << assign title here
...
关于xcode - 在AppKit中为macOS SwiftUI应用设置主窗口标题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59808404/