gpt4 book ai didi

swift - Cocoa 和 Swift 中的简单可点击链接

转载 作者:搜寻专家 更新时间:2023-10-31 08:13:06 26 4
gpt4 key购买 nike

我正在为 mac 10.11 快速编写一个桌面应用程序,我想添加一个链接到关于页面。

非常像这样:https://developer.apple.com/library/mac/qa/qa1487/_index.html

我找不到好的教程或引用。

任何帮助将不胜感激

最佳答案

swift 4、xCode 9

@IBDesignable
class HyperlinkTextField: NSTextField {

@IBInspectable var href: String = ""

override func resetCursorRects() {
discardCursorRects()
addCursorRect(self.bounds, cursor: NSCursor.pointingHand)
}

override func awakeFromNib() {
super.awakeFromNib()

// TODO: Fix this and get the hover click to work.

let attributes: [NSAttributedStringKey: Any] = [
NSAttributedStringKey.foregroundColor: NSColor.linkColor,
NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue as AnyObject
]
attributedStringValue = NSAttributedString(string: self.stringValue, attributes: attributes)
}

override func mouseDown(with theEvent: NSEvent) {
if let localHref = URL(string: href) {
NSWorkspace.shared.open(localHref)
}
}
}

关于swift - Cocoa 和 Swift 中的简单可点击链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38340282/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com