How to set NSButton's keyEquivalent to NSDownArrowFunctionKey in Swift

丶灬走出姿态 提交于 2019-12-13 05:05:00

问题


How do I set an NSButton's keyEquivalent (which is a String type) to the down arrow key in Swift? NSDownArrowFunctionKey is an Int.


回答1:


This page in Apple's documentation addresses this exact issue. The example they provide is written in Objective-C, the Swift equivalent is as follows:

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!
    @IBOutlet weak var button: NSButton!

    func applicationDidFinishLaunching(aNotification: NSNotification) {

        var array = [unichar(NSDownArrowFunctionKey)]
        button.keyEquivalent = NSString(characters: array, length: 1)
    }
}


来源:https://stackoverflow.com/questions/29357630/how-to-set-nsbuttons-keyequivalent-to-nsdownarrowfunctionkey-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!