如何在Swift中设置NSButton的key等效于NSDownArrowFunctionKey [英] How to set NSButton's keyEquivalent to NSDownArrowFunctionKey in Swift

查看:155
本文介绍了如何在Swift中设置NSButton的key等效于NSDownArrowFunctionKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Swift中将NSButton的keyEquivalent(字符串类型)设置为向下箭头键? NSDownArrowFunctionKey是一个整数.

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

推荐答案

页面解决了这一确切问题.他们提供的示例是用Objective-C编写的,Swift等效项如下:

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)
    }
}

这篇关于如何在Swift中设置NSButton的key等效于NSDownArrowFunctionKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆