Created
October 23, 2015 17:16
-
-
Save Isuru-Nanayakkara/f4034829077b5be8410a to your computer and use it in GitHub Desktop.
This is the Swift translation of the Apple's code snippet (https://developer.apple.com/library/mac/qa/qa1487/_index.html) displaying how to embed hyperlinks in NSTextField and NSTextView.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AppKit | |
extension NSAttributedString { | |
class func hyperlinkFromString(aString: String, withURL url: NSURL) -> NSAttributedString { | |
let attrString = NSMutableAttributedString(string: aString) | |
let range = NSMakeRange(0, attrString.length) | |
attrString.beginEditing() | |
attrString.addAttribute(NSLinkAttributeName, value: url.absoluteString, range: range) | |
attrString.addAttribute(NSForegroundColorAttributeName, value: NSColor.blueColor(), range: range) | |
attrString.addAttribute(NSUnderlineStyleAttributeName, value: NSNumber(integer: NSUnderlineStyle.StyleSingle.rawValue), range: range) | |
attrString.endEditing() | |
return attrString | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment