Mac Catalyst的自定义“关于应用程序”窗口

问题描述 投票:-1回答:1

更改Mac Catalyst的“关于应用程序”窗口?怎么做?

swift xcode menuitem maccatalyst
1个回答
0
投票

类似这样的东西:

#if targetEnvironment(macCatalyst)
extension AppDelegate {
override func buildMenu(with builder: UIMenuBuilder) {
    guard builder.system == .main else { return }

    // override about button
    builder.replaceChildren(ofMenu: .about) { (oldChildren) -> [UIMenuElement] in
        let menuElement = oldChildren.first
        if let uiCommand = menuElement as? UICommand {
            let aboutUICommand = UICommand(title: uiCommand.title,
            action: #selector(aboutApp(_:)))
            return [aboutUICommand]
        } else {
            return oldChildren
        }
    }
}

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        return super.canPerformAction(action, withSender: sender)
}

override func target(forAction action: Selector, withSender sender: Any?) -> Any? {
    if action == #selector(aboutApp) {
        return self
    } else {
        return nil
    }
}

@objc func aboutApp(_ selector: Any?) {
    guard let aboutTVC = AboutViewController.createInstance() else { return; }
    rootViewController?.present(aboutTVC, animated: true, completion: nil)
} 
} 
#endif
© www.soinside.com 2019 - 2024. All rights reserved.